Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set header in httppost/ httpget request

Tags:

android

i have a web service like " post -H 'Authorization: Token token="2hwhdh443hdhfh43j3jdej3j3"'. how to set this header in httpPost/ get request.

My code is here-

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);

but this gives HTML response. Please any one can guide me.

like image 204
Ritesh Kumar Singh Avatar asked Dec 20 '22 08:12

Ritesh Kumar Singh


1 Answers

Try removing "Content-Type" header and modify "Authorization" to -

request.addHeader("Authorization","Token token=2hwhdh443hdhfh43j3jdej3j3");

Working for me.

like image 51
Abhishek Avatar answered Feb 19 '23 14:02

Abhishek