如何在httppost/httpget请求中设置标题 [英] How to set header in httppost/ httpget request
本文介绍了如何在httppost/httpget请求中设置标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Web服务,例如"post -H'Authorization:Token token ="2hwhdh443hdhfh43j3jdej3j3"'.如何在httpPost/get request中设置此标头.
i have a web service like " post -H 'Authorization: Token token="2hwhdh443hdhfh43j3jdej3j3"'. how to set this header in httpPost/ get request.
我的代码在这里-
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost(MainActivity.baseUrl
+ "messages");
request.setHeader(new BasicHeader("Content-Type","application/json"));
request.setHeader(new BasicHeader("Authorization: Token","token= 2hwhdh443hdhfh43j3jdej3j3"));
response = client.execute(request);
但是会给出HTML响应.请任何人可以指导我.
but this gives HTML response. Please any one can guide me.
推荐答案
尝试删除"Content-Type"标头并将授权"修改为-
Try removing "Content-Type" header and modify "Authorization" to -
request.addHeader("Authorization","Token token=2hwhdh443hdhfh43j3jdej3j3");
为我工作.
这篇关于如何在httppost/httpget请求中设置标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文