HttpWebChilent上傳與下載進度條

搬砖的L先生發表於2024-03-15

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);

相關文章