This is what an PUT request with HttpClient and options could look like. You will need to transform your XMLData
, whatever that may be, to a string. The SO question provided by @Vikas in his comment mentions a few libraries that are effective at parsing XML.
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Injectable()
export class AppService {
constructor(private http: HttpClient) { }
doPut() {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'text/xml'
})
};
const xml: string = '<foo>1</foo>';
return this.http.put("/some/url", xml, httpOptions)
.subscribe(result => console.log(result));
}
}
Consolidated version if you prefer:
doPut(xml: string) {
return this.http.put("/some/url", xml, { headers: new HttpHeaders({ 'Content-Type': 'text/xml' }) })
.subscribe(result => console.log(result));
}
The HTTP request will NOT execute unless you subscribe()
to the returned Observable
produced by put()
somewhere. I'd additionally review the documentation for error handling and additional options/functionality.
Hopefully that helps!