繁体   English   中英

如何阻止Angular $ http反序列化响应正文?

[英]How can I stop Angular $http from deserializing the response body?

这个:

$http({method: 'GET', url: '/some/url/returning/json').
        success(function(data, status, headers, config) {
            console.log(data);
        });

显示Angular给我一个JavaScript对象作为success处理程序的第一个参数。 大概是通过嗅探响应的内容类型来尝试变得聪明。

这是不希望的行为。 如何告诉Angular将响应主体作为字符串给我?

不良行为是由Angular的transformResponse引起的。 要关闭此功能,请执行以下操作:

$http({method: 'GET', url: '/some/url/returning/json', transformResponse: [] }).
        success(function(data, status, headers, config) {
            console.log(data);
        });

它在文档中提到可以使用responseType config选项,大概是这样的:

$http({method: 'GET', url: '/some/url/returning/json', responseType: 'text'})...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM