Click here to Skip to main content
15,306,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
URGENTLY - need to sort this I have spent days on it
The web request is working for a POST method and I can get it working in Postman but my specific code is not working.

It is returning [] with a status of 200OK

Dim request2 As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("URL")
          request2.Method = "GET"
          request2.ContentType = "application/x-www-form-urlencoded"
          request2.KeepAlive = True
          request2.ContinueTimeout = 10000
          request2.Host = ""
          Dim Header2Collection As WebHeaderCollection = request2.Headers
          Dim BearerAccessToken =  "Bearer " & access_token 
          Header2Collection.Add("Authorization", BearerAccessToken)
          Header2Collection.Add("x-myobapi-key", "MYAPIKEY")
          Header2Collection.Add("x-myobapi-version", "v2")
          Header2Collection.Add("Accept-Encoding", "gzip,deflate")
  		  Header2Collection.Add("Cache-Control", "no-cache")
          Dim postBytes2 As Byte() = New UTF8Encoding().GetBytes(request2.ToString())
  		    Dim response2 As HttpWebResponse = CType(request2.GetResponse(), HttpWebResponse)
          	Dim receiveStream2 As Stream = response2.GetResponseStream()
          	Dim readStream2 As New StreamReader(receiveStream2)
  	        Dim jsonstring =readStream2.ReadToEnd()

What I have tried:

It has occassionally worked randomly but not clear why it is not working
Updated 23-Feb-21 22:36pm
Richard Deeming 24-Feb-21 4:38am
Nobody can tell you from looking at the client code why the server is returning an unexpected empty array as the response.

You need to debug the server-side code, if it's yours. Otherwise, you need to look at the documentation for the service you're trying to call to see what you're doing wrong.

NB: It makes no sense to set the request ContentType for a GET request, since GET requests don't have any content.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900