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
Error: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML>
<HEAD>
<TITLE>401 Authorization Required</TITLE>
<BASE href="/error_docs/"><!--[if lte IE 6]></BASE><![endif]-->
</HEAD>
<BODY>
<H1>Authorization Required</H1>
<P>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
<HR />
<ADDRESS>
Web Server at abrdome.com
</ADDRESS>
</BODY>
</HTML>
<!--
- Unfortunately, Microsoft has added a clever new
- "feature" to Internet Explorer. If the text of
- an error's message is "too small", specifically
- less than 512 bytes, Internet Explorer returns
- its own error message. You can turn that off,
- but it's pretty tricky to find switch called
- "smart error messages". That means, of course,
- that short error messages are censored by default.
- IIS always returns error messages that are long
- enough to make Internet Explorer happy. The
- workaround is pretty simple: pad the error
- message with a big comment like this to push it
- over the five hundred and twelve bytes minimum.
- Of course, that's exactly what you're reading
- right now.
-->
error in httputils2
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

VersioneOnline=3.13
<ChangeLog>- 3.13 -
- da codificare
- 3.12 -
- Minor Bug Fixex
- 3.11 -
- Bug Fixex
- Change Log dopo aggiornamento
- Modificata la selezione dei pasti
- Aggiunti i riepiloghi in PDF
- Aggiunta la possibilità di inserire delle note nell'ordine
- Aggiunta la lista ingredienti per ogni piatto
- Miglioramenti lato Server</ChangeLog>
<FileSize>
</FileSize>
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
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
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
Top