Answer the question
In order to leave comments, you need to log in
WebResponse hangs, how to fix?
public static async Task<string> POST(string url, string postfields)
{
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Timeout = 5000;
byte[] parameters = System.Text.Encoding.UTF8.GetBytes(postfields);
string res = null;
request.ContentLength = parameters.Length;
using(Stream stream = request.GetRequestStream())
{
stream.Write(parameters, 0, parameters.Length);
}
using (WebResponse response = await request.GetResponseAsync())
{
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
res = reader.ReadToEnd();
}
}
}
return res;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question