简体   繁体   中英

Postman is giving me the outputs of this endpoint but my localhost is giving me 400 error

Dont worry about the api_key as I am doing this just for practice. Earlier it was showing CORS error so i disabled it in chrome. But now its giving me GET https://api.yelp.com/v3/businesses/search?term=delis&latitude=37.786882&longitude=-122.399972 400 error.


function sendRequest () {
   var xhr = new XMLHttpRequest();
   xhr.open("GET", "https://api.yelp.com/v3/businesses/search?term=delis&latitude=37.786882&longitude=-122.399972",true);
   xhr.setRequestHeader("Accept","application/json");
   xhr.setRequestHeader("Authorization", "Bearer {i6LdgRRNDolECGnS0Q7MQf5c3-nNV9rciQdmNy6x0jBFGtBv8DlnCSd2erPEOlKOb6m63MFMj0UzEEINB58fmdZBgy0bW75qfrb4BtRQxZGFcmqczb3vFXjK6G9qYXYx}");
   xhr.onload = function(){
      if(this.status == 200){
         var users = JSON.parse(this.responseText);
         console.log(users)
      }
   }
   xhr.send(null);
}

use it

function sendRequest () {
   var xhr = new XMLHttpRequest();
   xhr.open("GET", "https://api.yelp.com/v3/businesses/search?term=delis&latitude=37.786882&longitude=-122.399972",true);
   xhr.setRequestHeader("Accept","application/json");
   xhr.setRequestHeader("Authorization", "Bearer i6LdgRRNDolECGnS0Q7MQf5c3-nNV9rciQdmNy6x0jBFGtBv8DlnCSd2erPEOlKOb6m63MFMj0UzEEINB58fmdZBgy0bW75qfrb4BtRQxZGFcmqczb3vFXjK6G9qYXYx");
   xhr.onload = function(){
      if(this.status == 200){
         var users = JSON.parse(this.responseText);
         console.log(users)
      }
   }
   xhr.send(null);
}

the { and } used for env and variable in postman (or other softwares usually)

in raw http request :


GET https://api.yelp.com/v3/businesses/search?term=delis&latitude=37.786882&longitude=-122.399972
Accept: application/json
Authorization: Bearer i6LdgRRNDolECGnS0Q7MQf5c3-nNV9rciQdmNy6x0jBFGtBv8DlnCSd2erPEOlKOb6m63MFMj0UzEEINB58fmdZBgy0bW75qfrb4BtRQxZGFcmqczb3vFXjK6G9qYXYx

postman have a feature that export requests in different programming language, use it to see efferent ( link )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM