Search code examples
.netvb.nethttpwebrequest

How to view HTTPWebRequest response?


Dim s As HttpWebRequest
Dim username= "username=" + HttpUtility.UrlEncode("username")
Dim message = "message=" + HttpUtility.UrlEncode("message")
Dim sep = "&"
Dim sb As New StringBuilder()
sb.Append(username).Append(sep).Append(message)
s = HttpWebRequest.Create("http://www.website.com/?" + sb.ToString())
s.Method = "GET"
Dim result = s.GetResponse()    

How do I reponse.write the result to the screen? I get errors like..Value of type 'System.Net.WebResponse' cannot be converted to 'String'.


Solution

  • s.GetResponse() returns a WebResponse, which isn't something you can just print. The actual response data is in result.Headers and result.GetResponseStream(). You'll need to read the data from that (the way you'd read any Stream) into a String, and THAT you can output to the screen.