HTTPCLIENT PACKAGE TUTORIAL

Cookies

Cookies will automatically be stored and used by HTTPClient when connecting to HTTP servers. Using cookies, it is possible to handle authentication for most websites. Cookies may also handled manually.

Retrieve the cookies from the first HTTP server normally.

cookies = URLFetch["www.wolfram.com", "Cookies", "StoreCookies"->False]
Out[0]=

By setting the option to False, cookies retrieved during the connection will not be stored in the global cookie share. The cookies can now be forwarded to future connections.

URLFetch["www.wolfram.com/mathematica", "Cookies", "Cookies"->cookies, "StoreCookies"->False]
Out[1]=

No cookies have been added to the global cookie share.

$HTTPCookies
Out[2]=

If the option is not set to False, cookies will by default be stored in a global cookie share and used for future connections.

URLFetch["wolfram.com", "Cookies"]
Out[3]=

This cookie is being stored globally.

$HTTPCookies
Out[4]=

This cookie will be available to all future connections. This same cookie will be used, for example, when connecting to http://reference.wolfram.com.

URLFetch["reference.wolfram.com", "Cookies"]
Out[5]=

Cookies are not persistent across different Mathematica sessions.

New to Mathematica? Find your learning path »
Have a question? Ask support »