Android Question Problem Poststring

jesuslizonsoluciones

Member
Licensed User
Longtime User
Hello to all

I am developing a software for hotels and to be able to manage the database. The first thing I have to do is to ask for authorization to the database and when I have it I get back a key.

So far I have not been able to access from my software, but from Postman I can access without problem.

In my software I have the following code and it always returns me that I am not authorized, I don't know if you can help me. Here is what I do and the code from postman that works.


thank you very much


Codigo:
'Data send for Postman Program***************************************************************************************

    

'    curl --location --request POST 'DireccionIpServidor/oauth/v1/tokens'

'    --header 'Content-Type: application/x-www-form-urlencoded'

'    --header 'x-app-key: 5171faa3-5308-49e9-aaaa-babbec18d478'

'    --header 'Authorization: Basic ZGVzYXJyb2xsb3F1aWNraW5fQ2xpZW50OktEMjIyRkU2cF9yak9iRy03Tld6QUNw'




'Body*********************



'    --data-urlencode 'username=OHIPSB_QUICKIN'

'    --data-urlencode 'password=Ly}bYD7$7l/U6/e7V#BFd'

'    --data-urlencode 'grant_type=password'


'End Body****************


'End Postman******************************************************************************************************       

    

    

    

    

    j.Initialize("", Me)

    

    j.Download(DireccionIpServidor  & "/oauth/v1/tokens")

    

    j.GetRequest.SetHeader("x-app-key","5171faa3-5308-49e9-aaaa-babbec18d478")

    j.GetRequest.SetHeader("Content-Type","application/x-www-form-urlencoded")

    j.GetRequest.SetHeader("Authorization","Basic ZGVzYXJyb2xsb3F1aWNraW5fQ2xpZW50OktEMjIyRkU2cF9yak9iRy03Tld6QUNw")

    

    j.Username="desarrolloquickin_Client"

    j.Password="KD22E6p_rjObG-7NWzACpK"

    

    j.PostString(DireccionIpServidor  & "/oauth/v1/tokens","username=OHIPSB_QUICKIN&password=Ly%7DbYD7%247l%2FU6%2Fe7V%23BFd&grant_type=password")

    

    

    Log(DireccionIpServidor  & "/oauth/v1/tokens")

    

    Wait For (j) JobDone(j As HttpJob)

    

    


    If j.Success Then
 

drgottjr

Expert
Licensed User
Longtime User
i would much prefer being able to test it myself, but i would suggest you try these changes:

1) DELETE: j.Download(DireccionIpServidor & "/oauth/v1/tokens")

2) since you are sending the username and password as the body, you might try
to DELETE: j.Username="desarrolloquickin_Client"
j.Password="KD22E6p_rjObG-7NWzACpK"

3) DELETE: j.GetRequest.SetHeader("Content-Type","application/x-www-form-urlencoded")
REPLACE WITH j.GetRequest.SetContentType("application/x-www-form-urlencoded")

4) Your handmade urlencoding of the password is probably OK, but you should use a recognized urlencoder method to handle things like that.

final version would look like:
B4X:
    j.Initialize("", Me)
    j.PostString(DireccionIpServidor  & "/oauth/v1/tokens","username=OHIPSB_QUICKIN&password=Ly%7DbYD7%247l%2FU6%2Fe7V%23BFd&grant_type=password")
    j.GetRequest.SetHeader("x-app-key","5171faa3-5308-49e9-aaaa-babbec18d478")
    j.GetRequest.SetContentType("application/x-www-form-urlencoded")
    j.GetRequest.SetHeader("Authorization","Basic ZGVzYXJyb2xsb3F1aWNraW5fQ2xpZW50OktEMjIyRkU2cF9yak9iRy03Tld6QUNw")
 
Upvote 0

jesuslizonsoluciones

Member
Licensed User
Longtime User
Hello

It works now, the problem was the SetContentType that I was sending inside the header. When I put it in j.GetRequest.SetContentType it works now.

Thank you very much
Resuelto problema:
    j.Initialize("", Me)
    
    j.Download(DireccionIPServidor  & "/oauth/v1/tokens")
    
    j.PostString(DireccionIPServidor  & "/oauth/v1/tokens","username=OHIPSB_QUICKIN&password=Ly}bYD7$7l/U6/e7V#BFdZZA&grant_type=password")
    j.GetRequest.SetHeader("x-app-key","3-5308-49e9-aaaa-babbec18d478")
    j.GetRequest.SetContentType("application/x-www-form-urlencoded")
    j.GetRequest.SetHeader("Authorization","Basic ZGVzYXJyb2xsb3F1aWNraW5fQ2xpZW50OktEMjIyRkU2cF9yak9iRy03Tld6QUNw")
    J.Username="desarrolloquickin_Client"
    J.Password="KD222FE6p_rjObG-7"
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…