Hi there I have been struggling to get what on the face of it appears a relatively simple call to an external API. As far as I can make out the code should work, but responds with 'Bad Request' here is the function that makes the call to the Login endpoint of the API:
Public Async Function GetToken(ByVal wsInstance As Integer) As Task(Of String)
Dim data As String = "{""password"":""" & _webServices(wsInstance).Pwd & """,""username"":""" & _webServices(wsInstance).Login & """}"
Dim requestMsg As New HttpRequestMessage(HttpMethod.Post, _clients(wsInstance).BaseAddress)
requestMsg.Headers.Add("Accept", "*/*")
requestMsg.Headers.Add("Accept", "application/json")
requestMsg.Content = New StringContent(data, Text.UTF8Encoding.Default, "application/json")
Dim response As HttpResponseMessage
response = _clients(wsInstance).SendAsync(requestMsg).Result
If (response.StatusCode = System.Net.HttpStatusCode.OK) Then
return response.Content.ToString
ElseIf (response.StatusCode = System.Net.HttpStatusCode.BadRequest) Then
Throw New BadHTTPRequestException("Bad HTTP Request With content: " & requestMsg.Content.ToString)
End If
End Function
The string variable 'data' contains the correct credentials (username and pwd obscured):
{"password":"########","username":"####.#######@##############.co.uk"}
Which on inspection are correct for the account defined on the destination system.
The baseaddress in this instance is the full url for the endpoint.
Quite possible that I am missing something fundamental here but for the life of me I can't see what it is.
Kind Regards Paul J