admin管理员组文章数量:1026989
I want to have some information about the response when I request an API with http in Ionic 2 / Angular 2. Informations like : response time, response size ... ect.
I use this code :
let url : "[myUrl]";
this.http.get(url).map(res => res.json()).subscribe(res => {
console.log(res);
});
I want to get the response header.
Someone know how to do that ? :)
I want to have some information about the response when I request an API with http in Ionic 2 / Angular 2. Informations like : response time, response size ... ect.
I use this code :
let url : "[myUrl]";
this.http.get(url).map(res => res.json()).subscribe(res => {
console.log(res);
});
I want to get the response header.
Someone know how to do that ? :)
Share Improve this question asked Dec 30, 2016 at 10:35 V. PivetV. Pivet 1,3285 gold badges26 silver badges60 bronze badges2 Answers
Reset to default 3this.http.get(url).map(res => {
console.log(res.headers); // Print http header
return res.json();
}).subscribe(res => {
console.log(res);
});
Angular Http
request returns an Observable
which contains all the information the server has passed. So you can access headers
from the response as res.headers
. To obtain the size of the response body you can use,
res.headers.get('Content-Length')
assuming this is present in the headers. So it depends on the information the response carries rather not what angular provides.
Response time information depends on what exactly you are looking for. For server response time in node.js
you can use this package. Then in response , response time
can be obtained with
res.headers.get('X-Response-Time')
If you want the total response time (including the network delay ) you will have use JavaScript
timer and find the time difference between request and response.
So the information you are looking for mainly relies on the server response rather than angular. And beware of CORS
in browser ( Access-Control-Expose-Headers
in response header ) . You can understand more about headers here. Hope it helps.
You can. In the map function you can get the all the information regarding HTTP call. You can do whatever you want with the result (I've added only a console.log)
this.http.get(url).map(res => {
console.log(res); // Print http details
return res.json();
}).subscribe(res => {
console.log(res);
});
I want to have some information about the response when I request an API with http in Ionic 2 / Angular 2. Informations like : response time, response size ... ect.
I use this code :
let url : "[myUrl]";
this.http.get(url).map(res => res.json()).subscribe(res => {
console.log(res);
});
I want to get the response header.
Someone know how to do that ? :)
I want to have some information about the response when I request an API with http in Ionic 2 / Angular 2. Informations like : response time, response size ... ect.
I use this code :
let url : "[myUrl]";
this.http.get(url).map(res => res.json()).subscribe(res => {
console.log(res);
});
I want to get the response header.
Someone know how to do that ? :)
Share Improve this question asked Dec 30, 2016 at 10:35 V. PivetV. Pivet 1,3285 gold badges26 silver badges60 bronze badges2 Answers
Reset to default 3this.http.get(url).map(res => {
console.log(res.headers); // Print http header
return res.json();
}).subscribe(res => {
console.log(res);
});
Angular Http
request returns an Observable
which contains all the information the server has passed. So you can access headers
from the response as res.headers
. To obtain the size of the response body you can use,
res.headers.get('Content-Length')
assuming this is present in the headers. So it depends on the information the response carries rather not what angular provides.
Response time information depends on what exactly you are looking for. For server response time in node.js
you can use this package. Then in response , response time
can be obtained with
res.headers.get('X-Response-Time')
If you want the total response time (including the network delay ) you will have use JavaScript
timer and find the time difference between request and response.
So the information you are looking for mainly relies on the server response rather than angular. And beware of CORS
in browser ( Access-Control-Expose-Headers
in response header ) . You can understand more about headers here. Hope it helps.
You can. In the map function you can get the all the information regarding HTTP call. You can do whatever you want with the result (I've added only a console.log)
this.http.get(url).map(res => {
console.log(res); // Print http details
return res.json();
}).subscribe(res => {
console.log(res);
});
本文标签: javascriptIonic 2Get the header of a response in http requestStack Overflow
版权声明:本文标题:javascript - Ionic 2 : Get the header of a response in http request - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745657284a2161673.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论