Android Question cUrl to B4A trouble

mw71

Active Member
Licensed User
Longtime User
Hi

i have become a example in cUrl:

curl \
-d "client_id=watch" \
-d "client_secret=....." \
-d "username=[user]" \
-d “scope=openid” \
-d "password=[password]" \
-d "grant_type=password" \
"href="https://......../protocol/openid-connect/token"


I have Test in B4A with:
B4X:
    h_Spot_Token.Initialize("",Me)
    h_Spot_Token.PostString(urlSpotV3_Token,$"client_id=watch&client_secret=.........&username=${box_User.Text}&password=${box_Pass.Text}&scope=openid&grant_type=password")"$)
    h_Spot_Token.GetRequest.SetHeader("Content-Type", "application/json")

    Wait For (h_Spot_Token) JobDone(h_Spot_Token As HttpJob)
    If h_Spot_Token.Success = True Then
        Log(h_Spot_Token.GetString)
    Else
        Log(h_Spot_Token.ErrorMessage)
    End If

unfortunately i get a Error: {"error":"invalid_request","error_description":"Invalid grant_type"}
 

DonManfred

Expert
Licensed User
Longtime User
While -d uses the application/x-www-form-urlencoded mime-type, generally understood by CGI's and similar, curl also supports the more capable multipart/form-data type. This latter type supports things like file upload.

So i would try to just use a PostMultiPart with an empfy file array giving the map with the data into the fields.

Edit: I interpreted it wrong/just the opposite. Please ignore my answer
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
thank for anser, now it works, after i have found the ....🤦‍♂️ Error:

grant_type=password")"$) -> Change to grant_type=password"$)
 
Upvote 0
Top