I'm trying to post request with JSON body using aurelia fetch client. Here is my code:
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)
});
}
}
However I get the following error in browser console:
Fetch API cannot load http://test.com/api/postdata. Response for preflight has invalid HTTP status code 404
The problem is that if I don't send json body (i.e. body: '') the request reaches the server! So, there's some issue with the body. Could you please help me to find out the root cause?