0

I'm trying to run an API on VB.net but it always goes to catch ex as Exception because it returns The Remote Server returned an error: (400) Bad Request. When I tried to run the API it on POSTMAN. The status is 400 Bad Request but the it has a response in JSON. How can I get JSON response on VB.Net using Try Catch?

Sample Code:

    Dim myRequest As HttpWebRequest
    Dim myResponse As HttpWebResponse = Nothing
    Dim myReader As StreamReader
    Dim address As Uri

    address = New Uri("https://test-api.com/test/transfers/10001/execute")
    myRequest = DirectCast(WebRequest.Create(address), HttpWebRequest)
    myRequest.Method = "PUT"
    myRequest.ContentType = "application/json"


try
        myResponse = DirectCast(myRequest.GetResponse(), HttpWebResponse)
        myReader = New StreamReader(myResponse.GetResponseStream())
catch ex As Exception
   MsgBox(ex.Message.ToString) 
'it goes here and returned The Remote Server returned an error: (400) Bad Request 
'i want to get the exception json response


End Try
momonsterrr
  • 436
  • 5
  • 18

0 Answers0