简体   繁体   English

AngularJS-获取响应头

[英]AngularJS - get headers in response

I'm doing a $http.get request to a https service which has an XML file and it need the headers('Content-length') to know it size. 我正在对具有XML文件的https服务执行$http.get请求,它需要headers('Content-length')知道它的大小。

This's my code: 这是我的代码:

$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);

});

The result of the request is: "headers is not a function" . 请求的结果是: "headers is not a function" Is there another way to get it? 还有另一种方法吗?

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

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

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