使用Javascript / ajax传递时无效的凭据

时间:2019-06-27 11:46:07

标签: javascript ajax api post

我正在尝试使用jquery发送POST请求,但它一直在说不正确的凭据。

我尝试过的

我在第一次Google搜索中尝试了大多数方法。我觉得我在这里做错了其他事情。例如

var auth = btoa('username:password');


var username = "username";
var password = "pass";

var auth = btoa('username:password');

console.log(auth);

var settings = {
  "url": "https://sct.intutrack.com/api/prod/trips/start",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization": "Basic " + auth
  },
  "data": {
    "tel": "9560688565",
    "src": "22.572646, 88.36389500000001",
    "dest": "28.6139391, 77.2090212",
    "srcname": "Intugine Technologies",
    "destname": "Bangalore",
    "client": "XYZ",
    "vendor": "Rivigo",
    "vehicle": "MH01x123",
    "invoice": "123ZXYZ",
    "eta_hrs": "75"
  }
};

$.ajax(settings).done(function(response) {
  console.log(response);
});

我遇到的错误

{"errorCode":403,"msg":"Invalid credentials","requestData":{"x-forwarded-for":"103.240.236.196","x-real-ip":"103.240.236.196","x-real-port":"22691","host":"sct.intutrack.com","connection":"close","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.9,la;q=0.8"}}

0 个答案:

没有答案