Axios发布方法:错误错误:请求失败,状态码为405

时间:2020-04-04 12:50:54

标签: javascript reactjs axios httprequest

我有一个简单的注册表格,用户可以在我的应用程序中注册,现在我想将提交的数据发送到另一个服务。

首先,我在邮递员面板中使用原始选项,如下测试邮递员的请求。

Api网址:app3.salesmanago.pl/api/contact/upsert

JSON DATA:
{
  "clientId":"w2ncrw06k7ny45umsssc",
  "apiKey":"ssssj2q8qp4fbp9qf2b8p49fz",
  "requestTime":1327056031488,
  "sha":"ba0ddddddb543dcaf5ca82b09e33264fedb509cfb4806c",
  "async" : true,
  "owner" : "adam@rce.com",
  "contact" : { 
        "email" : "test-1@konri.com",
        "name" : "Test",
        "address":{
            "streetAddress":"Brzyczynska 123",
      }
    }
}

我得到以下成功结果

{
    "success": true,
    "message": [],
    "contactId": "b52910be-9d22-4830-82d5-c9dc788888ba",
    "externalId": null
}

现在在我的本地主机中,我正在测试使用Axios post方法的react js向API发送数据,如下所示

// send data to sales manago
const sendSalesManagoData = () =>{
var current_timestamp = Date.now();
    axios({
        method: 'POST',
        url: 'app3.salesmanago.pl/api/contact/upsert',
        data: {
            clientId    : 'xxxxxxxxxxxxxxx',
            apiKey      : 'xxxxxxxxxxxxxxx',
            sha         : 'xxxxxxxxxxxxxxx',
            requestTime :  current_timestamp,
            owner       : 'xxxxxxxxxxxxxxx',
            contact:{
                user_id : user.id,
                email   : user.email,
                name    : `${user.first_name} ${user.last_name}`,
                industryType: companyIndustry,
            }   
        },
        headers: {
            'Accept'       : 'application/json',
            'Content-Type' : 'application/json',
        },

        }).then(function (response) {
            console.log(response);
        }).catch(function (error) {
            console.log('there is error', error);
    });
}

现在,当我发送数据时,出现以下错误。

(405 methods not allowed) there is error Error: Request failed with status code 405

enter image description here

我的代码有什么问题?

1 个答案:

答案 0 :(得分:0)

您必须在服务器上允许CORS。

Here is more information about CORS