我试图处理响应标头但不确定如何查询它们。这是代码段。当我试图阅读标题并对我注意到的内容发表评论时,我注释了几行。
$http({
method: 'POST',
url: URL,
data: $.param(data),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function (data,status,headers) {
//Need to process the header to understand the server response
//console.log(headers()); //This returns null
//console.log(headers('custom-myapp-text');// Obvisouls returns null as the headers() returns null
deferred.resolve();
});
return deferred.promise;
};
根据他们的documentation,'标题'返回一个函数??不确定如何根据此查询标头值。
data - {string | Object} - 用。转换的响应体 转换函数。
status – {number} – HTTP status code of the response. **headers – {function([headerName])} – Header getter function.** config – {Object} – The configuration object that was used to generate the request. statusText – {string} – HTTP status text of the response.
答案 0 :(得分:1)
我刚用一个有效的标题尝试过它,很好:
console.log(headers('Content-Length'));
此控制台在我的示例中记录了2
。它允许您访问任何有效的响应标头。