When you make multiple requests with HttpJob, cookies returned from the server are kept across the requests. This might be useful in some cases, but in other cases it is a problem as the web server will not send a new cookie if it is already present in the request.
In the following example a click on the button makes a request to http://marlar.dk/cookie.php which will set a cookie and then return the full cookie string.
At the first click no cookies are returned as there are none. But the script sets the cookie mycookie.Then, at subsequent requests, mycookie is sent to the server along with the request and returned by the script.
Adding j.GetRequest.RemoveHeaders("HTTP_COOKIE") as shown in the example doesn't work.
I have also looked at this post but I don't know if that applies here. Besides, what is hc in the code below?
How can I clear the cookies from HttpJob or simply make a new fresh request with no "memories" of the previous?
Example attached.
In the following example a click on the button makes a request to http://marlar.dk/cookie.php which will set a cookie and then return the full cookie string.
At the first click no cookies are returned as there are none. But the script sets the cookie mycookie.Then, at subsequent requests, mycookie is sent to the server along with the request and returned by the script.
B4A:
Dim j As HttpJob
j.Initialize("", Me)
j.Download("http://marlar.dk/cookie.php")
j.GetRequest.RemoveHeaders("HTTP_COOKIE")
Wait For (j) JobDone(j As HttpJob)
EditText1.Text = j.GetString
If EditText1.Text = "" Then EditText1.Text = "<none>"
j.Release
cookie.php:
setcookie("mycookie", "B4X");
echo $_SERVER["HTTP_COOKIE"];
Adding j.GetRequest.RemoveHeaders("HTTP_COOKIE") as shown in the example doesn't work.
I have also looked at this post but I don't know if that applies here. Besides, what is hc in the code below?
B4X:
Sub ClearCookies
Dim r As Reflector
r.Target = hc
r.Target = r.GetField("client")
r.Target = r.RunMethod("getCookieStore")
r.RunMethod("clear")
End Sub
How can I clear the cookies from HttpJob or simply make a new fresh request with no "memories" of the previous?
Example attached.