Android Question httputils2 and basic authentication problem

Discussion in 'Android Questions' started by n3t, Apr 13, 2015.

  1. n3t

    n3t Member Licensed User

    I have some problem with httputils2 and basic authentication.
    First when I call the .download method for a HttpJob the first connection is made without authentication and only on a second call the connection is ok (see the server log at bottom).

    And why I can not make a GET call with the chance to change the http header?
    job1.GetRequest.SetContentType("application/json; charset=UTF-8")
    job1.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0")
    job1.GetRequest.SetHeader("Authorization", "basic FEWSREWTREWTWT

    I attach a very simple demo.

    Code:
    Sub bLogin_Click

        
    Dim s_user, s_password As String
          s_user = 
    "info@xxxxxxxx.com"
          s_password= 
    "zzzzzzzz"


        
    Dim job1 As HttpJob
        job1.initialize(
    "Authentication", Me)
        
    ' with this url all ok (the 1° first connection hasn't then basic authentication
        'job1.Download("http://emea.extenua.com:888/root/Auth")

        
    ' with this url I failed alway
        job1.Download("http://emea.extenua.com:888/root/D_JHB5WSA47BFEDK3HDBLMEMJMZE/Auth")

        job1.Username = s_user
        job1.Password = s_password

        
    'job1.GetRequest.SetContentType("application/json; charset=UTF-8")
        'job1.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0")
        'job1.GetRequest.SetHeader("Authorization", "basic FEWSREWTREWTWT")

    End Sub
    Help would be greatly appreciated.





    with url "http://emea.extenua.com:888/root/Auth"

    ********** 1° request --> NO BASIC AUTH *******************
    REQUEST
    GET /root/Auth
    HTTP/1.1
    Host: emea.extenua.com:888
    Connection: Keep-Alive
    Cookie: mORMot_session_signature=3CA90EC9
    Cookie2: $Version=1

    RESPONSE
    HTTP/1.1 401 Unauthorized
    Content-Type: application/json; charset=UTF-8
    Server: mORMot/1.18.1204 (Windows) Microsoft-HTTPAPI/2.0
    X-Powered-By: Synopse mORMot 1.18.1204 http://synopse.info
    Server-InternalState: 16
    Accept-Encoding: synlz,gzip
    WWW-Authenticate: Basic realm="mORMot Server"
    Date: Mon, 13 Apr 2015 14:11:02 GMT
    Content-Length: 50

    {
    "errorCode":401,
    "errorText":"Unauthorized"
    }


    ********** 2 request --> BASIC AUTH *******************
    REQUEST
    GET /root/Auth
    HTTP/1.1
    Authorization: Basic aW5mb0BndWlkb3NvZnQuY29tOmV4dGVudWE=
    Host: emea.extenua.com:888
    Connection: Keep-Alive
    Cookie: mORMot_session_signature=3CA90EC9
    Cookie2: $Version=1

    RESPONSE
    HTTP/1.1 200 OK
    Content-Type: application/json; charset=UTF-8
    Set-Cookie: mORMot_session_signature=3CA90EC8; Path=/root
    Server: mORMot/1.18.1204 (Windows) Microsoft-HTTPAPI/2.0
    X-Powered-By: Synopse mORMot 1.18.1204 http://synopse.info
    Server-InternalState: 16
    Accept-Encoding: synlz,gzip
    Date: Mon, 13 Apr 2015 14:11:04 GMT
    Content-Length: 54

    {"result":1017712328,"logonname":"info@zzzzzzzz.com"}
     
    Last edited: Apr 13, 2015
  2. n3t

    n3t Member Licensed User

    Solved using PostString method and setting basic authentication into http header.
    Use base64 function to generate correct header.
     
    DonManfred and lemonisdead like this.
  3. DonManfred

    DonManfred Expert Licensed User

    You can post the complete solution

    For future references an example of showing exactly what you did and how to get this work would be nice to see for any users in future if they search for basic authentication
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice