Postman 生成的代码中的 postman-token 标头属性是什么? [英] What is the postman-token header attribute in generated code from Postman?

查看:58
本文介绍了Postman 生成的代码中的 postman-token 标头属性是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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-token attribute in the header. Why is it there?

参见 PHP Curl 示例:

See for example 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;
}

推荐答案

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

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.

查看文档/设置邮递员.

这篇关于Postman 生成的代码中的 postman-token 标头属性是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆