I am trying to get a token from a REST API. For this I use HttpClient. However, when reviewing the url that is sent in the request, it is automatically changed and removes the s from the https, leaving it as http and additionally places :10001 to the URL
I am programming in VS 2015 and the code I use is the following:
Public Async Function WSconHTTP(User As String, Passw As String) As Task
Dim client As HttpClient = New HttpClient()
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls
client.DefaultRequestHeaders.Accept.Clear()
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
Dim request As HttpRequestMessage = New HttpRequestMessage(HttpMethod.Post, "https://URLWEBxxx/IntegrationAPI_2/api/login")
Dim formData = New List(Of KeyValuePair(Of String, String))()
formData.Add(New KeyValuePair(Of String, String)("username", User))
formData.Add(New KeyValuePair(Of String, String)("password", Passw))
request.Content = New FormUrlEncodedContent(formData)
Dim response = Await client.SendAsync(request)
MessageBox.Show("Code status: " & response.StatusCode & vbCrLf & " Result: " & response.Content.ReadAsStringAsync().Result & vbCrLf , "Reply WS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Function
The response status code that the request gives me is: 404 and the result is:
"{""Message"":""No HTTP resource was found that matches the request URI "http://URLWEBxxx:10001/IntegrationAPI_2/api/login'.""}"
I appreciate the help you can give me.
What I have tried:
I have tried with other libraries such as restsharp but it has not worked for me
for this code disable this line
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls