Android Question Error in private page with OkHttpUtils2

AkuryuBR

Member
Hi to all, i have made a App based on httpUtils, i pick my entry with php page and mysql_maria db, all work fine, now i decie to use private page with .htpasswd ah .htaccess and here come the problem.

If i use this type of link http(s)/username:passwod@website.something in the browser (i have try with firefox and crome) all work fine, if i replace this link in the url of my app don't work, in the logs i read this
The link that i use for this try is http://prova:prova@beta.abrdome.com/emimangio/downloads/result.inf

and in the browser i read this thas is the file

I use the GET mode for my app with this library, you know if i can use the POST method ? Thanks
 

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
This is called Basic Authorization

B4X:
    Dim su As StringUtils
    Dim j As HttpJob
    j.Initialize("j",Me)
    j.Download("http://beta.abrdome.com/emimangio/downloads/result.inf")
    j.GetRequest.SetHeader("Authorization","Basic " & su.EncodeBase64("prova:prova".GetBytes("utf8")))  ' <--- username:password
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)
    End If
    j.Release
 
Upvote 0

AkuryuBR

Member
It Works!! Now remain the question about use POST method and not GET metod..
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
It Works!! Now remain the question about use POST method and not GET metod..
It is not matter POST or GET, it 'll work, because username/password added in header not body.
This is for POST:
B4X:
Dim su As StringUtils
Dim j As HttpJob
j.Initialize("j",Me)
j.PostString("http://beta.abrdome.com/emimangio/downloads/result.inf","")    ' <--- Post
j.GetRequest.SetHeader("Authorization","Basic " & su.EncodeBase64("prova:prova".GetBytes("utf8")))  ' <--- username:password
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
Else
Log(j.ErrorMessage)
End If
    j.Release
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…