【问题标题】:get 405 error while making post API call with token header使用令牌标头进行后 API 调用时出现 405 错误
【发布时间】:2015-11-30 16:43:42
【问题描述】:
   $.ajax({
            type: "POST",
            dataType: "json",
            url: "xxxxxxxxxxxxxxxxxxxxxxxxxx",
           //contentType: "application/json; charset=UTF-8",
            crossDomain: true,
            //xhrFields: { withCrendentials: true },
         //   beforeSend: function (req) {

              //  req.setRequestHeader('Access-Control-Allow-Origin', '*');
              //  req.setRequestHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
              //  req.setRequestHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
                //req.setRequestHeader("Authorization", "ST signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
               //     req.setRequestHeader("X-Mobile","false");
           //     },
                 headers: {

                "Authorization": "ST signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",


           },

            data: source,
            timeout: 10000,
            success: function (data) {

在 chrome 控制台上出现此错误

XMLHttpRequest 无法加载 url:xxxxxxxxxxxxxxxxxxxxx。请求的资源上不存在“Access-Control-Allow-Origin”标头。 Origin 'http://localhost:53208' 因此不允许访问

在 Mozilla 控制台上我收到此错误

跨域请求被阻止:同源策略不允许读取 url:xxxxxxxxxxxxxxxxxxxxxxxxx 处的远程资源。 (原因:CORS 标头“Access-Control-Allow-Origin”缺失)。

【问题讨论】:

    标签: ajax api post


    【解决方案1】:

    听起来xxxxxxxxxxxxxxxxxxx 没有实现CORS protocol。只要没有,您就无法通过 XMLHttpRequest 访问它。

    【讨论】:

    • 但是如何实现 CORS 呢?如果你有任何代码示例,你能解释一下吗
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-08
    • 2019-03-20
    相关资源
    最近更新 更多