const headers = new HttpHeaders({ 'Content-Type': 'text/xml' });
headers.append('Accept', 'text/xml');
headers.append('Content-Type', 'text/xml');
this.http.get('getxmlurl', {headers: headers}).subscribe(response => {
return '1234';
});
Run Code Online (Sandbox Code Playgroud)
嗨我正在使用angular 4 httpclient从spring控制器发出一个http get请求,它返回一个XML响应.
我遇到的问题是响应总是为空,即使我可以从chrome开发人员网络选项卡中看到xml响应.
我认为它可能与请求标题有关,angular 4默认为json但是我无法使用上面的代码更改请求标头.有人可以请一下建议.
谢谢
我正在使用Angular 6 httpClient并在服务中包含以下代码:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'text/xml' })
};
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(private http: HttpClient) { }
post() {
const postedData = { userid: 1, title: 'title here', body: 'body text' };
return this.http.post('this url here', postedData, httpOptions).subscribe(result => {
console.log(result);
}, error => console.log('There was an error: '));
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:我想发布一个xml文件,那么我该如何修改此代码呢?