Android Question HttpJob save received cookies

xor83

Member
Licensed User
Longtime User
Hello,

I am creating an app where I have to save login details/session for which I have to save cookies which I received from server, I am using HttpJob library and everything is working fine until I restart the app. How should I save details contained in HttpJob object? So that I don't have to ask user to login again. I need to save HttpJob object state may be serialize somewhere? Can anyone help me on this?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can get the response headers in hc_ResponseSuccess and set them as the job Tag property:
B4X:
Sub hc_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
   Response.GetAsynchronously("response", File.OpenOutput(TempFolder, TaskId, False), _
     True, TaskId)
   Dim job As HttpJob = TaskIdToJob.Get(TaskId)
   job.Tag = Response.GetHeaders
End Sub

Now you can check whether there is a Set-Cookie header and get the cookies from this header.
 
Upvote 0

xor83

Member
Licensed User
Longtime User
Thanks Erel for the reply.

What should I pass in this section?

B4X:
Sub JobDone(JobRes As HttpJob)
   Select JobRes.JobName
     Case "AppLogin"
       AppLogin_ResponseSuccess(job,JobRes.JobName)   ' << ResponseSuccess ?
   End Select
   JobRes.Release
End Sub
 
Last edited:
Upvote 0
Top