【问题标题】:What is the postman-token header attribute in generated code from Postman?Postman 生成的代码中的 postman-token 标头属性是什么?
【发布时间】:2019-01-12 04:08:51
【问题描述】:

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

参见 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;
}

【问题讨论】:

    标签: php rest curl postman


    【解决方案1】:

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

    请参阅文档/设置postman。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-15
      • 2021-08-27
      • 2015-11-25
      • 2021-05-20
      • 1970-01-01
      • 2021-09-03
      相关资源
      最近更新 更多