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等待完成.

上一篇:c#-如果内容为XML格式,如何在.NET Core 2.2中进行POST?


下一篇:CodeGo.net>如何获取时间到WebResponse的第一位?