【问题标题】:How to read/save HTTP Post response (HTML format) in angular 4如何以角度 4 读取/保存 HTTP Post 响应(HTML 格式)
【发布时间】:2020-06-25 11:26:25
【问题描述】:

我正在尝试读取 Angular 4 中的 HTTP Post 响应。但我做不到。因为响应是 HTML 格式。我搜索了许多网站,但找不到任何解决方案。

我可以读取 JSON 格式,但我不能读取 HTML。

请给我解决方案。

谢谢

【问题讨论】:

    标签: angular angular4-httpclient


    【解决方案1】:

    需要在options对象中添加responseType文本

    const options = {responseType: 'text'}
    this.http.post(url, body, options);
    

    【讨论】:

    • 感谢您的想法。它的工作很好。但我无法在此请求中添加标头。该怎么办?
    • 您应该能够将它们添加到选项对象中: const options = { headers: new HttpHeaders({ // your headers }), responseType: 'text' };也许称它为 httpOptions 会更有意义
    猜你喜欢
    • 2019-03-14
    • 1970-01-01
    • 2019-02-06
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    • 2021-01-28
    • 1970-01-01
    • 2016-05-31
    相关资源
    最近更新 更多