Jerez Active Member Licensed User Longtime User Aug 5, 2015 #1 Hi. I need help with this, please. This is my code to get a json string that works ok on my local network if i previously logged in locally (In Chrome for example). But in order to work without login in a browser i need to set a cookie first. How can i do that? How can i set a Cookie then save it and reuse in every next downloads? This is my current code: Code: Copy Dim job As HttpJob If Not (job.IsInitialized) Then job.Initialize("GET_DEVICES", Me) End If job.Download(Server & "/api/v2/devices/1") job.GetRequest.Timeout = 6000000 This is the API documentation in order to login with cookies: Code: Copy curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"form": true, "login": "admin", "password": "admin", "keepme": false, "default_ui": 1}' 192.168.0.62/api/v2/login -c cookie.txt Now we can execute with cookie: Code: Copy curl 192.168.0.62/api/v2/devices/1 -b cookie.txt Thanks for advise! Last edited: Aug 5, 2015
Hi. I need help with this, please. This is my code to get a json string that works ok on my local network if i previously logged in locally (In Chrome for example). But in order to work without login in a browser i need to set a cookie first. How can i do that? How can i set a Cookie then save it and reuse in every next downloads? This is my current code: Code: Copy Dim job As HttpJob If Not (job.IsInitialized) Then job.Initialize("GET_DEVICES", Me) End If job.Download(Server & "/api/v2/devices/1") job.GetRequest.Timeout = 6000000 This is the API documentation in order to login with cookies: Code: Copy curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"form": true, "login": "admin", "password": "admin", "keepme": false, "default_ui": 1}' 192.168.0.62/api/v2/login -c cookie.txt Now we can execute with cookie: Code: Copy curl 192.168.0.62/api/v2/devices/1 -b cookie.txt Thanks for advise!
Erel B4X founder Staff member Licensed User Longtime User Aug 5, 2015 #2 Cookies are set in the headers. Code: Copy Job.Download(...) Job.GetRequest.SetHeader("Cookie", "cookie data") Upvote 0
Cookies are set in the headers. Code: Copy Job.Download(...) Job.GetRequest.SetHeader("Cookie", "cookie data")
Jerez Active Member Licensed User Longtime User Aug 5, 2015 #3 Erel said: Cookies are set in the headers. Code: Copy Job.Download(...) Job.GetRequest.SetHeader("Cookie", "cookie data") Click to expand... Ok but in this case i need to download the 192.168.0.62/api/v2/login pass parameters as json/text, then get the response in job_done and then setHeader in next downloads? Upvote 0
Erel said: Cookies are set in the headers. Code: Copy Job.Download(...) Job.GetRequest.SetHeader("Cookie", "cookie data") Click to expand... Ok but in this case i need to download the 192.168.0.62/api/v2/login pass parameters as json/text, then get the response in job_done and then setHeader in next downloads?
Erel B4X founder Staff member Licensed User Longtime User Aug 6, 2015 #4 If the cookie is set by the server then it will happen automatically. Otherwise you need to manually add it to the downloads. Upvote 0
If the cookie is set by the server then it will happen automatically. Otherwise you need to manually add it to the downloads.
Jerez Active Member Licensed User Longtime User Aug 6, 2015 #5 Erel said: If the cookie is set by the server then it will happen automatically. Otherwise you need to manually add it to the downloads. Click to expand... Yeah!, thanks man! yesterday i've attached the cookie on every download and works fine! Upvote 0
Erel said: If the cookie is set by the server then it will happen automatically. Otherwise you need to manually add it to the downloads. Click to expand... Yeah!, thanks man! yesterday i've attached the cookie on every download and works fine!