捕获 HTTP 响应时出现问题
我有这段代码可以成功发出 HTTP 请求:
//Successful request
var requestInBytes = encoding.GetBytes(urlWithParameters.ToString());
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(urlWithParameters.ToString());
req.Method = "POST";
req.ContentLength = requestInBytes.Length;
req.ContentType = "application/x-www-form-urlencoded";
Stream newStream = req.GetRequestStream();
// Send the data.
newStream.Write(requestInBytes, 0, requestInBytes.Length);
newStream.Close();
但是,我在捕获响应时遇到了问题。现在,我正在尝试这样做:
//No response?
System.IO.StreamReader st = new StreamReader(((HttpWebResponse)req.GetResponse()).GetResponseStream());
var response = st.ReadLine();
但这会带来空白响应吗?
I have this code which successfully makes an HTTP request:
//Successful request
var requestInBytes = encoding.GetBytes(urlWithParameters.ToString());
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(urlWithParameters.ToString());
req.Method = "POST";
req.ContentLength = requestInBytes.Length;
req.ContentType = "application/x-www-form-urlencoded";
Stream newStream = req.GetRequestStream();
// Send the data.
newStream.Write(requestInBytes, 0, requestInBytes.Length);
newStream.Close();
However, I'm having trouble capturing the response. Right now, I'm trying this:
//No response?
System.IO.StreamReader st = new StreamReader(((HttpWebResponse)req.GetResponse()).GetResponseStream());
var response = st.ReadLine();
But this is coming back with a blank response?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
然后您可以检查响应的各种属性。
或者
尝试:
Try:
You can then check the various properties of the response.
OR
Try: