Reputation:
I am using Angular 6 and I have a Service which does a Json post call.
Here is the code:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(private http: HttpClient) { }
create(userId, title, body) {
const postedData = { userid: 1, title: title, body: body };
return this.http.post('https://jsonplaceholder.typicode.com/posts', postedData, httpOptions).subscribe(result => {
console.log(result);
}, error => console.log('There was an error: '));
}
}
My Question is: How can I change this so I can post XML instead?
Upvotes: 4
Views: 6549
Reputation: 18381
You need to change the encoding type in the headers of your post request 'Content-Type': 'text/xml';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'text/xml' })
};
Upvotes: 2