我尝试使用aurelia fetch客户端向JSON正文发布请求。这是我的代码:
import {inject, NewInstance} from 'aurelia-framework';
import {HttpClient, json} from 'aurelia-fetch-client';
@inject(NewInstance.of(HttpClient))
export class TestClass {
constructor(httpClient) {
this.__httpClient = httpClient.configure(x => {
x.useStandardConfiguration()
.withBaseUrl('http://test.com/api/')
});
}
sendRequest() {
let test= {
paramone: 'One',
paramtwo: 'Two'
};
this.__httpClient.fetch('postdata', {
method: 'post',
body: json(test)
});
}
}
但是我在浏览器控制台中收到以下错误:
Fetch API cannot load http://test.com/api/postdata. Response for preflight has invalid HTTP status code 404
问题在于,如果我不发送json正文(即正文:'')请求到达服务器!所以,身体存在一些问题。你能帮我找出根本原因吗?