开发者

Problems capturing HTTP response

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 bac开发者_如何学Ck with a blank response?


Try:

HTTPWebResponse response = req.GetResponse();

You can then check the various properties of the response.

OR

Try:

var response= req.ReadToEnd();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜