我正在尝试使用 xml 登录本地 Web 服务:
这是代码:
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'text/xml',
'Accept': 'text/xml',
'Response-Type': 'text'
})
};
login() {
const postedData = `
<authenticationDetail>
<userName>myusername</userName>
<password>mypassword</password>
</authenticationDetail>`;
return this.http.post('http://localhost/login.ws', postedData, httpOptions)
.subscribe(
result => {
console.log('This result is' + result);
},
error => {
console.log('There was an error: ', error);
}
);
}
我收到的错误是:
Http failure during parsing for 'http://localhost/login.ws'
这里有什么问题吗?我该如何解决这个问题?
最佳答案
尝试一下
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'text/xml',
'Accept': 'text/xml',
'Response-Type': 'text'
}),
responseType: 'text'
};
不仅在 header 中,而且在 httpOptions
中,responseType 必须设置为 text
。否则 Angular 会将调用的响应解析为 JSON。
关于javascript - Angular 5 - HttpClient XML Post - 解析期间 Http 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50231889/