ionic 3 HttpClient获取状态+发送标头 [英] ionic 3 HttpClient get status + send headers
本文介绍了ionic 3 HttpClient获取状态+发送标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在离子3上使用了HttpClientModule,我想在我的api上做一个获取
i'm using the HttpClientModule on ionic 3, and i want to do a get on my api
let email = "test@email.com";
let password = "password";
let headers = new HttpHeaders();
this.http.get('http://127.0.0.1:8000/api/login',{
headers: {'email':email,'password':password}
});
我不想获得json但只是请求的状态,因为做类似的事情:
i don't want to get the json but only the status of the request, for doing something like :
if(status == 200) { ... }
esle { ... }
你能帮我吗?
谢谢
推荐答案
在http.get方法的标题选项和中添加观察:'响应'订阅使get()方法获得任何你想要的响应状态..
Add observe : 'response' in header options of http.get method and subscribe to get() method to get response status whatever you want..
this.http.get('http://127.0.0.1:8000/api/login',{
headers: {'email':email,'password':password},observe: 'response'
}).subscribe(
res => { console.log(res) ;
if(res.status==201)
{
//do action
}else
{
}
},
这篇关于ionic 3 HttpClient获取状态+发送标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文