How can I set a cookie in a request using Fiddler?


Cookies Problem Overview

I need to set a cookie before I issue a request to a Web site using Fiddler. How do I do this?

Cookies Solutions

Solution 1 - Cookies

Simple...You need to set a header value, with your request, like so:

Cookie: YourCookieName=YourCookieValue

Solution 2 - Cookies

To do this using the FiddlerScript engine, add the following code into the onBeforeRequest method:

oSession.oRequest["Cookie"] = (oSession.oRequest["Cookie"] + ";YourCookieName=YourCookieValue");

This will preserve any other cookies that have been set.

Solution 3 - Cookies

You need to be more specific about what you're trying to do.

You can edit (or add) an outbound Cookie header to send a cookie to the website. You can do this either manually or via the FiddlerScript engine. But that doesn't "set" the cookie on the client-- it simply sends it to the server. If you want to set a cookie on the client, you either have to use another means, or you can inject a Set-Cookie response header on a previous response from the server, with the value you want to set on the client.

Solution 4 - Cookies

You can also use the Fiddler Composer.

  1. Run Fiddler
  2. Open the Composer Tab on the top.

It's easiest if you can start with another request from your web site. To do this capture a the request you want to modify, then drag it from the UI to the composer tab.

A good explanation is here:

Solution 5 - Cookies

Fiddler allows your to resend/rebuild an existing request. There is a Request Builder. While rebuilding in the RAW form, modify your cookies.

Solution 6 - Cookies

This solution is valid for Cookie based authentication:

If you want to test the API/url which have authentication enabled, please try following, i am showing for MVC web API on IIS server. usually there are more than 1 cookie responsible for authorization, so you may need to send more than 1 cookie in header as follows:

User-Agent: Fiddler Host: localhost:51000 content-Type: application/json Cookie : .ASPXAUTH=xxxxx;ASP.NET_SessionId=yyyy;__RequestVerificationToken=zzzz

Solution 7 - Cookies

When running Fiddler as a reverse Proxy you can modify the response headers via FiddlerScript by adding a line in the OnBeforeResponse method:

static function OnBeforeResponse(oSession: Session) {
    // ...
    oSession.oResponse["Set-Cookie"] = "sessionToken=abc123; Expires=Wed, 09 Jun 2021 10:18:14 GMT";

Also check Fiddler docs about Modifying a Request or Response for more info.


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJeremy McGeeView Question on Stackoverflow
Solution 1 - CookiesRayLovelessView Answer on Stackoverflow
Solution 2 - CookiesDesLFCView Answer on Stackoverflow
Solution 3 - CookiesEricLawView Answer on Stackoverflow
Solution 4 - CookiesRich WagenknechtView Answer on Stackoverflow
Solution 5 - CookiesankitjaininfoView Answer on Stackoverflow
Solution 6 - CookiesashishView Answer on Stackoverflow
Solution 7 - CookiesThomasView Answer on Stackoverflow