【问题标题】:GET error code 404 (Not Found)获取错误代码 404(未找到)
【发布时间】:2018-03-08 05:45:37
【问题描述】:

按照我之前的post,我得到了

 XHR finished loading: POST  "http://partners.api.skyscanner.net/apiservices/pricing/v1.0".

似乎 POST 工作正常,但对于 GET:

 GET
 http://testdomain.com:3000/undefined?apiKey=APIKEY&stops=0&duration=360&includeCarriers=ba;u2;af
 404 (Not Found)

Uncaught (in promise) Error: Request failed with status code 404
    at createError (bundle.js:23687)
    at settle (bundle.js:23657)
    at XMLHttpRequest.handleLoad (bundle.js:23529)

这是代码的一部分:

axios(authOptions)
.then(function(response){
    console.log("response ====> ", response.headers);
    console.log("--->", response.headers.Location);
    /*
    console.log("data is: ", response.data);
    console.log("response.request.responseURL: ", response.request.responseURL );
    console.log("response headers", response.headers);
    console.log("location headers: ", response.headers.location);
    */
   var newAuthOpts = {
        method: 'GET',
        url: response.headers.Location + '?apiKey=APIKEY&stops=0&duration=360&includeCarriers=ba;u2;af',
        data: querystring.stringify(data),
        json: true
    };
    axios(newAuthOpts).then(function(response) {
        console.log(response);
    });
})
.catch(function(error){
    console.log(error);
});

return {
    type: FETCH_LOCALS, 
    payload: data
};

我正在尝试从标题中获取正确的 url:response.headers.location,但这返回未定义,我找不到错误。有人可以帮忙吗?

【问题讨论】:

    标签: get http-headers axios es6-promise


    【解决方案1】:

    response.headers.locationresponse.headers.Location 之间存在很大差异 - JavaScript 中的所有内容都区分大小写。换句话说,两个版本可以共存并被视为完全不同的属性。正是出于这个原因,camelCase 被普遍使用。通过这种方式,我们可以很容易地将其识别为错误,例如,当属性以大写字母开头时。

    【讨论】:

      猜你喜欢
      • 2021-09-06
      • 1970-01-01
      • 2015-02-20
      • 2016-01-18
      • 2021-03-31
      • 2021-10-07
      • 2019-06-13
      • 2021-03-08
      • 2019-08-17
      相关资源
      最近更新 更多