Wow*_*owa 9 c# timeout http-post httpwebrequest
我如何使用POST上传一个大字符串(在我的情况下使用BLOB的XML)而不使用GetResponse获取Timeout?
更改超时有帮助,但这不是一个真正的解决方案.如果服务器确实死亡或POST中断,我必须等待极端大超时.
任何的想法?
HttpWebRequest webRequest = null;
string response = "";
byte[] bytes = Encoding.UTF8.GetBytes(xml);
try
{
webRequest = (HttpWebRequest)WebRequest.Create("http://" + this.host + ":" + this.port);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
webRequest.Timeout = 5000;
webRequest.ContentLength = bytes.Length;
using (Stream requeststream = webRequest.GetRequestStream())
{
requeststream.Write(bytes, 0, bytes.Length);
requeststream.Close();
}
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))
{
response = sr.ReadToEnd().Trim();
sr.Close();
}
webResponse.Close();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
return response;
Run Code Online (Sandbox Code Playgroud)
是的,这几乎是预期的 http 行为。
选项:
| 归档时间: |
|
| 查看次数: |
7339 次 |
| 最近记录: |