繁体   English   中英

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

[英]Axios post method: There is error Error: Request failed with status code 405

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

首先,我使用 postman 测试我的请求,如下所示,使用 postman 面板中的原始选项。

Api url: 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
}

现在在我的本地主机中,我正在测试使用 react js 和Axios post方法将数据发送到 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

在此处输入图像描述

我的代码有什么问题?

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

这是有关 CORS 的更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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