2016-04-27 32 views
15

Negli ultimi giorni ho usato il postino per esplorare un'interfaccia REST. Inoltre ho usato Postman per la generazione di codice delle ricerche REST. Qualunque sia la lingua del programma di destinazione, Postman aggiungerà sempre un attributo postman-token nell'intestazione. Perché è lì?Qual è il token postino nel codice generato da Postman?

Vedi ad esempio 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; 
} 

risposta

15

Questo è principalmente usato per bypassare un bug in Chrome. Se un XMLHttpRequest è in sospeso e viene inviata un'altra richiesta con gli stessi parametri, Chrome restituisce la stessa risposta per entrambi. L'invio di un token casuale evita questo problema. Questo può anche aiutarti a distinguere tra le richieste sul lato server.

Vedere documenti/impostazioni postman.