I am stuck on a login request to web API. So the process is simple I have to send “username”, “password” and “grant_type” to the server along with the two headers “Accept” and “Content-Type”. If the user is valid my app will receive the following response from the server:
Now in the subsequent request I have to send the token.
I tried to send a request with Download2 and PostString but couldn’t get any response and the request was time out with code 400.
below is my code to send request.
P.S. I tried it using Postman the request is working fine
B4X:
{
"access_token": "XXXX",
"token_type": "bearer",
"expires_in": 86399
}
Now in the subsequent request I have to send the token.
I tried to send a request with Download2 and PostString but couldn’t get any response and the request was time out with code 400.
below is my code to send request.
B4X:
Private Sub btnEnter_Click
Dim j As HttpJob
Dim Map1 As Map
If txtName.Text<>"" And txtPassword.Text<>"" Then
Dim strName As String = txtName.text
Dim strPassword As String = txtPassword.text
j.Initialize("", Me)
j.Download2("http://xxxxx.azurewebsites.net/oauth/token", _
Array As String("username",strName,"password",strPassword,"grant_type","password"))
j.GetRequest.SetContentType("application/x-www-form-urlencoded")
j.GetRequest.SetHeader("Accept", "application/json")
j.GetRequest.SetHeader("Content-Type", "application/json")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
End If
Log("Err! " & j.GetString)
j.Release
Else
Msgbox("Enter all fields and try again","Login")
End If
End Sub
P.S. I tried it using Postman the request is working fine
Last edited: