和邮递员一起送饼干

我读过邮递员用 cookie 发送请求的手册:

由于打包的应用程序在沙箱中与浏览器分开运行,因此 无法访问浏览器内设置的 Cookie。此限制可以 也可以使用拦截器扩展克服。邮递员路线所有 请求,然后使用浏览器上下文 发送请求。浏览器中设置的 Cookie 将自动 请阅读“拦截者”上的原始博客文章。

一旦启用了拦截器,您还可以从 只要设置“ Cookie”头,Cookie 就会被发送 你也可以访问那些 回复时可用。请查看博客文章 更多

所以我下载了谷歌 Chrome 的拦截器,它启用了。

此外,我还向邮递员添加了以下内容: Cookie JSESSIONID=daczcz36789

当我查看网络时,我注意到 Cookie 没有被发送。

我做错了什么?

243370 次浏览

You can enable Interceptor in browser and in Postman separately. For send/recieve cookies you should enable Interceptor in Postman. So if you enable interceptor only in browser - it will not work. Actually you don't need enable Interceptor in browser at all - if you don't want to flood your postman history with unnecessary requests.

You should enable your interceptor extension man manually, it locate in the top-right of your postman window. There are several buttons, find the interceptor button and enable it, then you can send cookies after set Cookie field in your request headers.

I was having issues getting this working (on OSX). I'd followed the instructions provided by Postman, and the advice here, and cookies were still not being set.

However, the post above saying "So if you enable interceptor only in browser - it will not work" alerted me to the fact that the interceptor could be enabled in the browser as well as in Postman itself. I thought I'd try switching it on in the browser, to see if that helped, and it did. I then switched it off in the browser, and it still worked.

So, if you are having issues getting it working, I'd suggest trying switching it on in browser at least once, as, for me, this seemed to trigger it into life. I think you will still need it switch on in Postman too.

Even after toggling it did not work. I closed and restarted the browser after adding the postman plugin, logged into the site to generate cookies afresh and then it worked for me.

Enable intercepter in this way

Basically it is a chrome plug in. After installing the extention, you also need to make sure the extention is enabled from chrome side.

enter image description here

Chrome apps including Postman are being deprecated as mentioned here. Now the recommendation is to go for native apps which are not detached from the sandboxed environment of the browser.

Quoting from the feature page:

FEATURES EXCLUSIVE TO THE NATIVE APPS:

COOKIES: The native apps let you work with cookies directly. Unlike the Chrome app, no separate extension (Interceptor) is needed.

BUILT-IN PROXY: The native apps come with a built-in proxy that you can use to capture network traffic.

RESTRICTED HEADERS: The latest version of the native apps let you send headers like Origin and User-Agent. These are restricted in the Chrome app. DON'T FOLLOW

REDIRECTS OPTION: This option exists in the native apps to prevent requests that return a 300-series response from being automatically redirected. Previously, users needed to use the Interceptor extension to do this in the Chrome app.

MENU BAR: The native apps are not restricted by the Chrome standards for the menu bar.

POSTMAN CONSOLE: The latest version of the native apps has a built-in console, which allows you to view the network request details for API calls.

So once you install the native Postman app from here you don't have to go looking for additional prerequisites like interceptor app just to check your cookies. I didn't have to change a single setting after installing the native postman app and all my cookies were visible in Cookies tab as shown below:

enter image description here

Based @RBT's answer above, I tried Postman native app and want to give a couple of additional details.

In the latest postman desktop app, you can find the cookies option on the extreme right:

enter image description here

You can see the cookies for your localhost (these cookies are linked with the cookies in your chrome browser, although the app is running natively). Also you can set the cookies for a particular domain too.

enter image description here

I used the postman chrome extension until it became deprecated. Chrome extension is also less usable and powerful than the native postman application. Hence it became very inconvenient to use the chrome extension.

I have found another approach:

  1. copy any request in chrome/any other browser as a CURL request copy curl request
  2. import to postman copied request import to postman copied request
  3. save imported request in the postman's list