View and Set HTTP headers for Safari/Chrome

2019-04-04 00:53发布

问题:

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?

回答1:

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.



回答2:

Another popular chrome app for this is is Postman



回答3:

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



回答4:

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.



回答5:

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"]);


回答6:

you can use Modify Headers extension in chrome.



回答7:

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.