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

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

问题描述

在最后几天,我使用邮递员探索REST接口。我还使用Postman来生成REST查询的代码。无论目标程序的语言是什么,Postman将总是在标题中添加一个 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){
echocURL Error#:。$ err;
} else {
echo $ response;
}


解决方案


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


请参阅docs / settings postman


During last days I used postman to explore a REST interface. Also I used Postman for code generation of REST querys. Whatever the target programminlanguage is, Postman will always add a postman-token attribute in the header. Why is it there?

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

解决方案

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.

See docs/settings postman.

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

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