Reputation: 116
I am trying to call post XML data in angular & get posted XML in python(Django) and save it to mongodb, but its giving mi error 406 (Not Acceptable) and detail":"Could not satisfy the request Accept header.
In component.ts :
let headers = new Headers();
headers.append('Content-Type', 'application/xml');
headers.append('Accept', 'application/xml');
let body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " +
"<note> " +
"<to>Tove</to> " +
"<from>Jani</from> " +
"<heading>Reminder</heading> " +
"<body>Dont forget me this weekend!</body> " +
"</note>";
this.http.post(url, body, { headers: headers })
.subscribe(data => {
console.log(data);
});
In views.py
def post(self, request):
original_response = request.data
save_response = LenderResponse(lender_response=str(original_response))
return Response(original_response)
Upvotes: 1
Views: 4450
Reputation: 984
406: Not Acceptable
means that the server cannot return the data in the format that you requested using the Accept
header.
You are passing the Accept: application/xml
header, but for some reason, your server does not support that response type. you should either pass a different header with a format the server knows how to work with or change the server code to support the application/xml
response type.
For Django (as it looks to be your server framework of choice), you should use the REST Framework XML plugin.
Upvotes: 2