Cookies from request

994
2
Jump to solution
07-15-2019 03:17 AM
GarethWalters2
New Contributor III

Hi,

I have an API that I want to access that stores the authentication information in a cookie.

I can successfully make the initial login request, however the second request to add data doesn't work as I can't access the cookies that were created from the initial request (or should be).

I can do the testing in Postman, but nothing happens if I take the http code and make a couple of NetworkRequests or even a function based on the html code from Postman.

I have read the docs and it looks like I need to access the QNetworkCookieJar to get this done (which currently isn't available) unless there is some wise advice from the QML experts that could help.

Look forward to hearing from someone

0 Kudos
1 Solution

Accepted Solutions
StephenQuan1
Esri Contributor

Cookie management should be automatic.

If the login attempt was done via a NetworkRequest, then, it would set the cookies for all subsequent NetworkRequest. So, any session cookies should be working automatically.

Whilst one shouldn't need to, you can read the cookie header given to you from a server via the responseHeaders and feed them into subsequent NetworkRequest headers.

View solution in original post

2 Replies
StephenQuan1
Esri Contributor

Cookie management should be automatic.

If the login attempt was done via a NetworkRequest, then, it would set the cookies for all subsequent NetworkRequest. So, any session cookies should be working automatically.

Whilst one shouldn't need to, you can read the cookie header given to you from a server via the responseHeaders and feed them into subsequent NetworkRequest headers.

GarethWalters2
New Contributor III

Hi Stephen,

Thanks for writing and helping me solve this. the initial request created a key in the header called 'Set-Cookie' which does have the value I needed to carry on, however the subsequent requests required a value from that "Set-Cookie" to be added as its own key/value pair - Cookie.

Once I set that prior to sending request it all worked perfectly.

Thank again.

Gareth