Gene

Gene

  • NA
  • 6
  • 2.1k

Restsharp API Asp.net VB.Net empty response

Feb 7 2023 2:54 AM

I am trying to pass api request and get a response on button click in Asp.net 4.61 with VB.net. Then the response will show in a textbox, however I never get a response and it doesnt even seem my login is hitting the API as no attempts show up in the API log. I had something like this working the other day and my stupid hard drive died! Trying to rewrite it but I have missed something clearly. I do not get any errors just no response. I am able to use postman and get a response to the same url thanks i advance here is a sample of my code
 

Imports Newtonsoft.Json
Imports RestSharp
Imports System
Imports System.Threading.Tasks

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim restClient As RestClient = New RestClient("myurl.com/ws/rest/userid=myid&password=password")
        ' restClient.Timeout = -1
        Dim request As RestRequest = New RestRequest(Method.Post)
        request.AddHeader("X-API-Key", "MYAPIKEY")
        request.AddHeader("Content-Type", "application/xml")
        Dim body = "MY Body Request XML Redacted"
        request.AddParameter("application/xml", body, ParameterType.RequestBody)
        Dim result As RestResponse = restClient.Execute(request)
      
       txtXMLTEXTBoxTest.Text = result.Content
    End Sub


 


Answers (2)