angular - 通过 Angular 中的 post 请求传递 responseType: 'blob'
问题描述
我通过获取请求传递 responseType: 'blob'。它运作良好。
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { RequestOptions, Response, ResponseContentType } from '@angular/http';
let headers = new HttpHeaders();
headers = headers.set('Content-Type', 'application/pdf');
return this.http.get(url, {
headers: headers,
responseType: 'blob'
}
如何通过 post 请求传递相同的 responseType?
我试过了 :
const headers = new Headers({
'Content-Type': 'application/pdf'
});
const options = new RequestOptions({headers: headers});
options.responseType = ResponseContentType.Blob;
return this.http.post(url, body, options)
但它不起作用。我有错误消息:类型参数 '{ headers: Headers; }' 不可分配给“RequestOptionsArgs”类型的参数。属性“标题”的类型不兼容。类型“标题”不可分配给类型“标题”。
UPD 以下评论我已重新提出请求:
const headers = new HttpHeaders({ 'Content-Type': 'application/pdf'});
return this.http.post(url, body, { headers, responseType:'blob' })
它运作良好!非常感谢!
解决方案
推荐阅读
- bash - TeamCity - 测试一些端点并处理结果。坚持处理结果,如何将其从 TC 发送到可视化
- python - 由于 gcc 错误,无法使用 pip 安装 sasl
- windows - 有没有办法从 Windows SDK 上的红外传感器获取无人机的高度?
- mysql - mysql查询连接两个表以查找未出现在右表上的元素
- reactjs - Express 或 react 正在删除标题
- jquery - 在 Google Chat 中创建新话题 - 如何发送新的指定话题密钥?
- javascript - 我如何在reactjs中更新获取请求
- json - 如何在golang中打印json值
- ios - iOS 订阅 DID_CHANGE_RENEWAL_STATUS 通知:latest_expired_receipt vs latest_receipt
- android - TouchOpacity 组件设置为在 android 中定位绝对不可点击