Android Question Insert a cookie using HTTPJob.GetRequest.SetHeader

Discussion in 'Android Questions' started by lentunti, Jul 9, 2015.

  1. lentunti

    lentunti Member Licensed User

    Hi all,

    Is it possible to use HTTPJob.GetRequest.SetHeader to replicate a cookie like this one in CookieManager:-

    CookieManager1.SetCookie("https://devtablet.nwhub.co.uk/api/jobs/fetchJobs", "NWTABLETGATEWAYSESSION=lg9f3d66b04k77dfusek9bmfl5")

    I have to apply to to a HttpJob.download2 as opposed to a WebView.

    Is this possible?

    I have tried
    HTTPJob.GetRequest.SetHeader("SET-COOKIE", "NWTABLETGATEWAYSESSION=lg9f3d66b04k77dfusek9bmfl5; path=https://devtablet.nwhub.co.uk/api/jobs/fetchJobs")
    but it doesn't seem to work

    Thanks for any help.

    regards
    Lee
     
  2. sonicmayne

    sonicmayne Member Licensed User

  3. Erel

    Erel Administrator Staff Member Licensed User

    You need to set "Cookie" not "Set-Cookie". Set-Cookie header is used by the server (in the response) to ask the browser to set the cookies.
     
  4. lentunti

    lentunti Member Licensed User

    This is now my code :-
    getJobs.download2("https://devtablet.nwhub.co.uk/api/jobs/fetchJobs", Array As String ("action", JSONstring))
    getJobs.GetRequest.SetHeader("Cookie", "NWTABLETGATEWAYSESSION=lg9f3d66b04k77dfusek9bmfl5; path=https://devtablet.nwhub.co.uk/api/jobs/fetchJobs")

    Which now gives me an internal server error. Your you say that thus suggests that the cookie has worked but there is a problem on the server (Possible dumb question).

    thanks for your help.

    Lee
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Note that cookies are managed automatically by HttpUtils2 (actually HttpClient). If the server has previously returned this cookie then you do not need to manually add it to the request.
     
Loading...