用邮递员发送饼干

Sending cookies with postman

我看了postman用cookie发送请求的手册:

As the packaged app runs in a sandbox separately from the browser, it can not access cookies set inside the browser. This restriction can also be overcome using the Interceptor extension. Postman routes all requests through the Interceptor, which then uses the browser context to send requests. Cookies set inside the browser are automatically attached to your requests. Read the original blog post on Interceptor.

Once the interceptor is enabled, you can also send cookies from Postman. Just set the "Cookie" header, and the cookie will be sent with the request. You can also get access to cookies that are available when the response is returned. Check out out blog post for more

所以我下载了 google chrome 的拦截器,它启用了。

此外,我将以下内容添加到邮递员中:Cookie JSESSIONID=daczcz36789

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

我做错了什么?

您可以在浏览器和 Postman 中分别启用拦截器。对于 send/recieve cookie,您应该在 Postman 中启用拦截器。因此,如果您仅在浏览器中启用拦截器 - 它不会起作用。实际上,您根本不需要在浏览器中启用拦截器 - 如果您不想让不必要的请求淹没您的邮递员历史记录。

您应该手动启用您的拦截器扩展 man,它位于您的 postman window 的右上角。有几个按钮,找到拦截器按钮并启用它,然后在请求头中设置Cookie字段后就可以发送cookie了。

我在运行时遇到了问题(OSX)。我已按照 Postman 提供的说明和此处的建议进行操作,但仍未设置 cookie。

但是,上面的 post 说 "So if you enable interceptor only in browser - it will not work" 提醒我拦截器可以在浏览器和 Postman 本身中启用。我想我会尝试在浏览器中打开它,看看是否有帮助,确实如此。然后我在浏览器中关闭它,它仍然有效。

因此,如果您在使用它时遇到问题,我建议您至少尝试在浏览器中将其打开一次,因为对我来说,这似乎会触发它的运行。我认为您仍然需要在 Postman 中打开它。

即使在切换之后它也不起作用。我在添加邮递员插件后关闭并重新启动浏览器,登录到站点重新生成 cookie,然后它对我有用。

以这种方式启用拦截器

基本上它是一个chrome插件。安装扩展后,您还需要确保从chrome端启用扩展。

Chrome 如前所述 here,包括 Postman 在内的应用已被弃用。现在建议使用未脱离浏览器沙盒环境的本机应用程序。

引用自专题页面:

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.

因此,一旦您从 here 安装了本机 Postman 应用程序,您就不必为了检查您的 cookie 而寻找其他先决条件,例如拦截器应用程序。安装本机邮递员应用程序后,我不必更改单个设置,并且我的所有 cookie 都在 Cookies 选项卡中可见,如下所示:

根据上面@RBT 的回答,我尝试了 Postman 本地应用程序并想提供一些额外的细节。

在最新的postman桌面应用程序中,您可以在最右侧找到cookies选项:

您可以看到本地主机的 cookie(这些 cookie 与您的 chrome 浏览器中的 cookie 链接,尽管该应用程序是 运行 本机)。您也可以为特定域设置 cookie。

我使用邮递员 chrome 扩展,直到它被弃用。 Chrome 扩展的可用性和功能也不如本机邮递员应用程序。因此使用 chrome 扩展名变得非常不方便。

我找到了另一种方法:

  1. 将 chrome/any 其他浏览器中的任何请求复制为 CURL 请求
  2. 导入邮递员复制的请求
  3. 将导入的请求保存在邮递员列表中