我正在尝试使用 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>
财产 -
static get properties() {
return {
apiEndPoint: {
type: String,
value: 'http://example.com'
},
requestOtpBody: {
type: String,
computed: '_createRequestOtpBody(mobileNumber)',
notify: true
}
};
}
计算函数 -
_createRequestOtpBody(mobileNumber) {
let body = {
phone_number: "+91" + mobileNumber
}
return JSON.stringify(body);
}
这不起作用,404 Bad request。我需要向我的服务器发送一个 JSON 对象。
错误信息-
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