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
GenePosted Feb 7, 2023, 12:55 PM
I tried that it, it acted exactly the samw way. I send the URL the same way in postman and it works fine. IN VB the API doesnt even login at all.
Naimish MakwanaPosted Feb 7, 2023, 3:59 AM
Hello Gene,
Your API endpoint URL is not correct as it has query parameters in it which should not be part of the URL. The API endpoint should only contain the base URL,
The query parameters lshould be added as parameters to the REST request.
Please try below code and check.
Thanks
Naimish Makwana