2016-07-04 100 views
2

我正在做一个$http.get请求到https服务,该服务有一个XML文件,它需要headers('Content-length')知道它的大小。AngularJS - 获取标题的响应

这是我的代码:

$http({ 
    method : "GET", 
    url : "https://url.com/xml_file.xml" 
}).then(
    function sCallback(data, status, headers, config, statusText) { 

    console.log(headers('Content-Length')); 

}, function eCallback(data, status, headers, config, statusText) { 

    $log.warn(data, status, headers, config, statusText); 

}); 

请求的结果是:"headers is not a function"。 有没有另一种方法来获得它?

+1

你在做这件事?你为什么期望这样做? – Amit

+0

是的,我正在这样做。我需要这个价值来进行验证。这应该根据文档 –

+0

工作[我如何从跨域Ajax请求访问Content-Length标头?](http://stackoverflow.com/questions/4850288/how-can-i-access- content-length-header-from-a-cross-domain-ajax-request) – Sherbrow

回答

-1

console.log(data.headers('Content-Length')); 
 
console.log(data.headers('Content-type'));

+0

不适用于我的内容类型esists,但内容长度不存在。我发现服务器使用邮递员回复内容长度。试图修改transformResponse包含单个函数(输入){返回输入;} – Rantiev

+0

你真的试过这个,或者只是写代码来给出答案? –

+0

@FoyzulKarim:是的 – Prianca