2016-07-04 90 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