简体   繁体   中英

HttpWebRequest The request was aborted: The operation has timed out

I am trying to upload a long video to jwplatform with the help of HttpWebRequest .I have set the Timeout as below . when i upload data it throw error.

The request was aborted: The operation has timed out

Event though the server timeout is along enough to weight for response but i still returning the same error.

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(callUrl);
            request.ContentType = "multipart/form-data; boundary=" +
                                    boundary;
            request.Method = "POST";
            request.KeepAlive = true;
            request.Timeout= 24*60*60*1000;
...
            using (var response = request.GetResponse())
            {
                Stream stream2 = response.GetResponseStream();
                StreamReader reader2 = new StreamReader(stream2);
                res = reader2.ReadToEnd();
            }

I am using the GetResponse() mathod as above.

Any help on how i can force the webrequest to wait until the data is fully upload will be highly appreciated. Thanks in Advance.

You can use request.GetResponseAsync (). and so use asynchronous task to wait properly the response.

To help you, it'll be something like this :

public  async Task<string> InfoAnswerAsync(WebRequest request)
 { 
using (var response = await request.GetResponseAsync())
{
    using (var stream = response.GetResponseStream())
        if (stream != null)
            using (var reader = new StreamReader(stream))
            {
                return await reader.ReadToEndAsync();
            }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM