2

Im working on an old VB.NET (ASP.NET) web page, and I need to get the response for an HttpWebRequest call as follows:

Dim s As HttpWebRequest
Dim enc As UTF8Encoding
Dim postdatabytes As Byte()
s = httpWebRequest.Create("www.theurl.com/api")
enc = New System.Text.UTF8Encoding()
Dim PostData = "grant_type=client_credentials"
postdata = postdata & "&client_id=" & ConfigurationManager.AppSettings("client_id")
postdata = postdata & "&client_secret=" & ConfigurationManager.AppSettings("client_secret")
postdata = postdata & "&audience=" & ConfigurationManager.AppSettings("audience")
postdatabytes = enc.GetBytes(postdata)
s.Method = "POST"
s.ContentType = "application/x-www-form-urlencoded"
s.ContentLength = postdatabytes.Length

Using stream = s.GetRequestStream()
      stream.Write(postdatabytes, 0, postdatabytes.Length)
End Using
Dim result = s.GetResponse()
response.write(result)

The problem I have is that, instead of getting the Json string I get with Postman, I get this when response writing "result":

System.Net.HttpWebResponse

Any ideas?

Thanks!

1 Answer 1

1

For those looking for an answer, I made it work by adding the following code:

Dim responsedata As Stream = result.GetResponseStream
Dim responsereader As StreamReader = New StreamReader(responsedata)
Dim xResponse = responsereader.ReadToEnd
Response.Write(xResponse)

Thanks.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.