php Postman 生成的代码中的 postman-token 标头属性是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36883046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:58:29  来源:igfitidea点击:

What is the postman-token header attribute in generated code from Postman?

phprestcurlpostman

提问by d4rty

I have been using postman to explore a REST interface. When using Postman's code generation feature, regardless of which programming language I select, Postman will always add a postman-tokenattribute in the header. Why is it there?

我一直在使用邮递员来探索 REST 接口。在使用 Postman 的代码生成功能时,无论我选择哪种编程语言,Postman 都会postman-token在 header 中添加一个属性。为什么会在那里?

See for example PHP Curl:

参见示例 PHP Curl:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(CURLOPT_URL => "https://myURL.com,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
  "authorization: Basic abcdefghijklmnop",
  "cache-control: no-cache",
  "postman-token: wt53gwg-e9bb-645d-g53d-e42f8765aut0"
  ),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

回答by d4rty

This is primarily used to bypass a bug in Chrome. If an XMLHttpRequest is pending and another request is sent with the same parameters then Chrome returns the same response for both of them. Sending a random token avoids this issue. This can also help you distinguish between request on the server side.

这主要用于绕过 Chrome 中的错误。如果 XMLHttpRequest 处于挂起状态,并且使用相同参数发送了另一个请求,则 Chrome 会为它们返回相同的响应。发送随机令牌可避免此问题。这也可以帮助您区分服务器端的请求。

See docs/settings postman.

请参阅文档/设置邮递员