如何停止角$ HTTP从反序列化响应主体? [英] How can I stop Angular $http from deserializing the response body?

查看:119
本文介绍了如何停止角$ HTTP从反序列化响应主体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

显示,角是给我一个JavaScript对象作为第一个参数,以我的成功处理程序。 presumably,它试图通过嗅探内容类型响应的要聪明。

shows that Angular is giving me a JavaScript object as the first argument to my success handler. Presumably, it is trying to be smart by sniffing the content-type of the response.

这是意外的行为。我该如何告诉角度给我的响应体作为一个字符串?

This is undesired behavior. How do I tell Angular to give me the response body as a string?

推荐答案

的意外行为由角的 transformResponse 引起的。要关闭此功能,这样做:

The undesired behavior is caused by Angular's transformResponse. To turn this off, do:

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

这篇关于如何停止角$ HTTP从反序列化响应主体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆