[英]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.