How do I manually set a cookie in a script?

Some sites use cookies to tell them additional information about the client making a request. Simply put, cookies are intended as a way to convey state in the otherwise stateless HTTP protocol.

In most cases, it’s not necessary to manually set a Cookie header. Loadster automatically receives Set-Cookie headers from your server and regurgitates the cookies like any other HTTP user agent. However, if you need to manually send a cookie from your script that was not received from the server, here is how you would do it.

First of all, click the Add… menu on the step you want to add the cookie for, and choose Add request header.

Adding a custom header

Enter the header name of “Cookie” and the header value as the key-value pair. For this example, we’ll go with a cookie name of “a” and a value of “1”.

Setting a Cookie header

After playing your script, you’ll see a message about the custom request header in the logs:

The custom Cookie header appears in the logs

You can also drill into the request to view the exact headers that were sent:

The custom Cookie header appears in the results tree

You can read more about the Cookie header in general on the Mozilla Developer Network.