HttpWebChilent上传与下载进度条

HttpClientHandler hand = new HttpClientHandler();
ProgressMessageHandler processMessageHander = new ProgressMessageHandler(hand);
HttpClient localHttpClient = new HttpClient(processMessageHander);

HttpRequestMessage httpRequestMessage = new HttpRequestMessage();

httpRequestMessage.Method = HttpMethod.Put;
httpRequestMessage.Content = new StreamContent(content);

//for upload
processMessageHander.HttpSendProgress += (sender, e) =>
{
int num = e.ProgressPercentage; //you can use HttpProgressEventArgs e
};

//for download
// processMessageHander.HttpReceiveProgress += (sender, e) =>
// {
// int num = e.ProgressPercentage;
// };

HttpResponseMessage test = await localHttpClient.SendAsync(httpRequestMessage);

posted @ 2024-03-15 10:47  搬砖的L先生  阅读(18)  评论(0编辑  收藏  举报