【发布时间】:2019-10-24 07:18:46
【问题描述】:
服务器正在向我发送 XML 响应,但我无法使用 HttpClient angular 8 获取它。在 Postman 中,它工作正常。
尝试将 responseType 设为“blob”。尝试使用 HttpOptions。尝试使用 header Allow-Encoding gzip 等。
let url = "My server URL";
let body = "My xml content in string";
const headers = new HttpHeaders()
.set('Accept', 'text/xml')
.set('Content-Type', 'text/xml')
.set('userid', 'xxxx')
.set('password', 'xxxx')
.set('authkey', 'xxxxxxxxxxxxxxx');
this.httpClient.post(url, body, {headers: headers, responseType: 'text'})
.subscribe(resonse => {
console.log(resonse);
}, err => {
console.error(err);
});
预期:XML 响应 实际:空字符串("")
【问题讨论】:
-
尝试将其作为纯文本发送,然后解析为 xml
-
可能是网址不完全相同?你能分享一下浏览器的开发工具输出吗?
-
@brandt.codes
Cross-Origin Read Blocking (CORB) blocked cross-origin response https://xxxxxx.org/API/xmlapi2.aspx with MIME type text/plain. See https://www.chromestatus.com/feature/5629709824032768 for more details. -
这是一个 CORS (de.wikipedia.org/wiki/Cross-Origin_Resource_Sharing) 问题。您的代码是正确的。
标签: angular