C#中的getResponse无法正常工作.没有回应回来
作者:互联网
我在C#中有以下代码:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/x-www-form-urlencoded";
request.Timeout = 30000;
request.Method = "POST";
request.KeepAlive = true;
request.AllowAutoRedirect = false;
Stream newStream = request.GetRequestStream();
newStream.Write(bPostData, 0, bPostData.Length);
byte[] buf = new byte[1025]; int read = 0; string sResp = "";
HttpWebResponse wResp = (HttpWebResponse)request.GetResponse();
Stream resp = wResp.GetResponseStream();
HttpWebResponse wResp = …行刚刚挂起(因为URL没有响应).我不确定它到底在哪里崩溃(因为我什至没有得到异常错误).我在IE中测试了URL,它工作正常.我还检查了bPostData,并且其中有数据.
哪里出了问题?
解决方法:
尝试在变量newStream中关闭请求流.也许API等待完成.
标签:httpwebresponse,httpwebrequest,c 来源: https://codeday.me/bug/20191102/1992624.html