简体   繁体   English

iron-ajax不支持POST请求的content-type ='application / json'

[英]iron-ajax not support content-type='application/json' for POST request

I am trying to use iron-ajax but the content-type='application/json' is not supporting. 我正在尝试使用iron-ajax,但是content-type ='application / json'不支持。

<iron-ajax id="ajaxRequestOtp"
                               method="POST"
                               url="[[apiEndPoint]]/user-sms-auth"
                               body="{{requestOtpBody}}"
                               handle-as="json"
                               headers='{"Accept": "application/json"}'
                               on-response="_responseRequestOtp"
                               on-error="_errorResponseRequestOtp"
                               content-type='application/json'>
                    </iron-ajax>

Property - 物业-

static get properties() {
            return {
                apiEndPoint: {
                    type: String,
                    value: 'http://example.com'
                },
                requestOtpBody: {
                    type: String,
                    computed: '_createRequestOtpBody(mobileNumber)',
                    notify: true
                }
            };
        }

Computed function - 计算功能-

_createRequestOtpBody(mobileNumber) {
            let body = {
                phone_number: "+91" + mobileNumber
            }
            return JSON.stringify(body);
        }

This is not working, 404 Bad request. 404错误请求,因此无法正常工作。 I need to send a JSON object to my server. 我需要将JSON对象发送到我的服务器。

Error Message- 错误信息-

OPTIONS http://example.com/user-sms-auth 404 (Not Found)
(index):1 Failed to load http://example.com/user-sms-auth: Response for preflight has invalid HTTP status code 404

Make requestOtpBody => type: Object , and skip the JSON.stringify step. 使requestOtpBody => type: Object ,并跳过JSON.stringify步骤。

_createRequestOtpBody(mobileNumber) {
    return { phone_number: "+91" + mobileNumber };
}

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

相关问题 Ajax中的JSON字符串发布请求内容类型application / formdata与application / json - JSON string in ajax post request content-type application/formdata vs application/json Sails js http post 请求,内容类型为:application/json - Sails js http post request with content-type: application/json 烧瓶中没有POST请求和Content-Type“application / json”的响应 - No response with POST request and Content-Type “application/json” in flask 使用Iron-ajax发布json对象作为application / x-www-form-urlencoded - Post json object with iron-ajax as application/x-www-form-urlencoded iron-ajax绑定并将JSON写入文件 - iron-ajax bind and write JSON to file 当'Content-Type'设置为'application / json'时,无法发送帖子请求 - Can't send a post request when the 'Content-Type' is set to 'application/json' ajax请求标头在开发服务器上具有内容类型application / json,但在生产环境中具有text / html - ajax request header has content-type application/json on dev server but text/html on production $ .ajax post请求标头字段不允许Content-Type CORS - $.ajax post Request header field Content-Type is not allowed CORS AngularJS无法使用Content-Type:application / json发送post请求 - AngularJS can't send post request with Content-Type:application/json Ajax Post内容类型:应用程序/ Json阻止请求 - Ajax Post Content Type : Application / Json Block the request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM