Android Question HTTPUtills2 get cookie and Webview set cookie ?

senat56

Member
Licensed User
Longtime User
I want to get a cookie from JobDone and transfer them to the WebView. How?o_O
 

warwound

Expert
Licensed User
Longtime User
Have a look at my CookieManager library.

If you are dealing with secure HTTP - HTTPS - CookieManager is unlikely to work and you'll need a different technique.
I have some code that'll work with cookies over HTTPS - let me know if you need it.

Martin.
 
Upvote 0

senat56

Member
Licensed User
Longtime User
Have a look at my CookieManager library.

If you are dealing with secure HTTP - HTTPS - CookieManager is unlikely to work and you'll need a different technique.
I have some code that'll work with cookies over HTTPS - let me know if you need it.

Martin.
See how I want to do! There is a certain site I log into it using HTTP utils2. Then manipulate the site ... and operelenny moment I have to show some's page in the webview, but it will not let me on the right page, because I'm not authorized by him. So I would like to receive the cookie and shove them webview!
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
If you were using the HTTP library then you could add code such as this to the Sub that handles the ResponseSuccess event:

B4X:
Sub HttpClient1_ResponseSuccess (Response As HttpResponse, TaskId1 As Int)
   Log("HttpClient1_ResponseSuccess")
   Log("TaskId: "&TaskId1)
   
   Log("** Headers **")
   Dim Headers As Map=Response.GetHeaders
   Dim i As Int
   Dim Key, Value As String
   For i=0 To Headers.Size-1
     Key=Headers.GetKeyAt(i)
     Value=Headers.GetValueAt(i)
     Log(Key&" : "&Value)
   Next
   
   Response.Release
End Sub

You can see that the response headers are available as a B4A Map object and with HTTP (as opposed to HTTPS) you'll probably find one of these headers is the cookie you want.
If you can get that cookie from the HttpResponse and try CookieManager to set it so it's now available to any WebView in your application you might find that's all thats required.

Martin.
 
Upvote 0

senat56

Member
Licensed User
Longtime User
Thanks for the mentioned algorithm! But I've tried it, and there's a problem! Now I will describe
In the beginning I used the HTTP library all was well until I had poprobyval on android 4.1., Previously tested at 2.2 and all was well.
But by 4.1
There is an exception in
HttpClient1_ResponseSuccess (Response As HttpResponse, TaskId1 As Int)
on line Response.GetString exception android.os.networkonmainthread
And I was advised to use http util2.
Now I do not know how to be (
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Well i've searched for 'httputils2 getheaders' and found no way in which you can access the headers when using HttpUtils2.

With ICS and later versions of Android, all networking must be done in it's own thread - not on the main UI thread.
HttpUtils2 takes care of this threading for you - so it has that advantage - but unless you can access the headers it is of limited use.

Maybe someone (Erel?) will read this thread and comment.

Maybe you'd be best to start a new thread 'HttpUtils2 GetHeaders?'?

Martin.
 
Upvote 0
Top