I'm testing an API and I would like to hit it with safari and see the raw json that's returned. The API requires a certain HTTP header be sent with every request. Is there a way in Safari or Chrome to set my http headers when visiting a URL?
-
I believe there are a few limitations to the core system that won't allow for extensions to be made that do this, I don't know if that has changed recently though... – sg3s Aug 17 '11 at 18:20
-
Well, just don't get your hopes up... Chrome development is pretty damn rapid so maybe they fixed it and/or added options to do this. – sg3s Aug 17 '11 at 18:27
-
1You can also force an accept header by ending your URI with .json, or .xml, etc. – Rob Carpenter Nov 13 '13 at 21:14
-
This answer could be useful http://stackoverflow.com/a/27936481/816213 – Sachin Jain Jan 14 '15 at 05:41
8 Answers
There are a couple Google Chrome apps that do this. One is called Rest Console. I actually found an app called GraphicalHttpClient in the Mac AppStore that's a lot easier and more enjoyable to use.

- 17,354
- 2
- 34
- 52

- 21,708
- 19
- 73
- 121
-
3
-
@christian-schlensker This answer has become irrelevant, both the links are dead. You may want to accept the latest answer - https://stackoverflow.com/a/68128919/816213 – Sachin Jain Oct 10 '22 at 12:20
-
Possible without using app? Would be nice to click logs and just quickly see JSON. – Oliver Dixon Jun 24 '16 at 09:00
Header Hacker will do the job on the Chrome browser and Modify Headers on the FireFox browser. Both of them allow to set custom HTTP Headers

- 83,883
- 25
- 248
- 179
-
I am looking for a simple extension which can replace **response** (not request) headers, but Header Hacker seems to be for requests only and Redirector seems to be able to do it, offering "Response Header" in the selection of replacement modes, but it does not seem to work. The WebRequest API should permit to replace response headers, but I am unable to develop a Chrome extension myself and do not have enough time to learn it. Other than using a local filtering proxy like Fiddler, I have no idea how to solve this in Chrome directly. Do you? – kriegaex Sep 02 '12 at 11:22
-
Update: Chrome extension Redirector works now and does what I need. There seemed to be a caching issue. – kriegaex Sep 02 '12 at 12:09
The (currently experimental) WebRequest API lets you do view and modify headers: http://code.google.com/chrome/extensions/trunk/webRequest.html
It's pretty easy to view headers using onSendHeaders
.
To edit headers, you'll need to block the request. This sample (from the docs linked to above) removes the User-Agent header from all requests:
chrome.experimental.webRequest.onBeforeSendHeaders.addListener(
function(details) {
delete details.requestHeaders['User-Agent'];
return {requestHeaders: details.requestHeaders};
},
{},
["blocking"]);

- 9,406
- 4
- 36
- 44

- 8,220
- 2
- 36
- 33
I would use Fiddler as my debugging proxy and set the header there. See the "Add a request header" of the FiddlerScript CookBook. This same solution would work with any browser.
Fiddler is a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect all HTTP(S) traffic, set breakpoints, and "fiddle" with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET language.

- 41,386
- 23
- 126
- 155
If you are on Chrome you can use the Modify Headers rule in Requestly
Here's a screenshot of the Header Modification Rule
Requestly also has a feature that lets users share the rules with each other. Here's an example of a headers rule I created - https://app.requestly.io/rules/#sharedList/1624596871428-Stackoverflow-answer
To use it, follow the link and click on Import List to modify it as per your use case.
To modify headers in Safari, one can use Requestly Desktop App
Other References

- 21,353
- 33
- 103
- 168

- 625
- 10
- 25
I know answer has already been chosen, however I thought I would share also:
EasyHTTP in Mac App Store. https://itunes.apple.com/gb/app/easyhttp/id657224426?mt=12
It's free, easy to use and pretty good.

- 12,264
- 26
- 124
- 193