【问题标题】:AngularJS - get headers in responseAngularJS - 获取标题作为响应
【发布时间】:2016-11-06 13:21:38
【问题描述】:

我正在向具有 XML 文件的 https 服务发出 $http.get 请求,它需要 headers('Content-length') 才能知道它的大小。

这是我的代码:

$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"。 有没有其他方法可以获取?

【问题讨论】:

标签: javascript angularjs xml https


【解决方案1】:

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

【讨论】:

  • 对我不起作用,内容类型存在,但内容长度不存在。我看到服务器使用邮递员响应内容长度。已尝试将 transformResponse 修改为包含单个函数(输入){return input;}
  • 你是真的试过这个还是只是写了代码来给出答案?
  • @FoyzulKarim:是的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多