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 back with a blank response?
HTTPWebResponse response = req.GetResponse();
You can then check the various properties of the response.
var response= req.ReadToEnd();