如何使用 POSTMAN 客户端 post 凭据创建基于 cookie 的会话

How to post credentials using POSTMAN client to create a cookie based session

我正在使用 postman 客户端对 JIRA 进行 REST 调用 API。它说 "POST your credentials to http://jira.example.com:8090/jira/rest/auth/1/session" 获取 SESSION。我尝试使用 Form-data、application/x-www-form-urlencoded、raw 等发布。没有任何效果。这是正确的方法。

这是我正在关注的教程:https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-cookie-based-authentication

由于您使用的是邮递员,我假设您处于开发环境中。在这种情况下,使用 auth header 可能更简单,它是 base-64 编码的 username/password。来自文档 here:

Supplying Basic Auth headers

If you need to you may construct and send basic auth headers yourself. To do this you need to perform the following steps: Build a string of the form username:password Base64 encode the string Supply an "Authorization" header with content "Basic " followed by the encoded string. For example, the string "fred:fred" encodes to "ZnJlZDpmcmVk" in base64, so you would make the request as follows.

curl -D- -X GET -H "Authorization: Basic ZnJlZDpmcmVk" -H "Content-Type: application/json" "http://kelpie9:8081/rest/api/2/issue/QA-31"

在 Postman 的 Headers 部分,添加 AuthorizationBasic <base64-encoded-username:password>

别忘了将 header Content-Type 添加为 application/json

(您可以使用 base64encode.org 快速编码您的 username/password)。 不要忘记将字符串作为 username-colon-password (username:password)

如果你和我在同一个UI上postman,点击Authorization,select一个auth type(我成功使用了basic auth),然后输入你的凭据.接下来单击 body 选项卡,select raw,在右侧的下拉菜单中选择 JSON(applications/json),然后正常提供 body。

这是第一关。下一个可能遇到的障碍(也是我遇到的障碍)是一旦您的基本身份验证被接受,JIRA 将拒绝访问作为代码 403 的跨站点请求伪造检查 (XSRF) 的一部分。我有一张票open right now seeing if there is a possible workaround to post and put from postman, 因为使用 postman 和 newman 比构建一个我必须的完整插件要简单得多跳过一堆箍来访问。

使用 Postman 只需将 withCredentials:true 添加到您的请求 header 部分。