Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android set content type HttpPost

Tags:

How can you change the content-type of a HttpPost in android?

For a request I need to set the content type to application/x-www-form-urlencoded

So i got this bit of code:

httpclient=new DefaultHttpClient(); httppost= new HttpPost(url); StringEntity se = new StringEntity("");  se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/x-www-form-urlencoded")); httppost.setEntity(se); 

But that doesn't do the trick and I cant find the solution anywhere.

Cheers

like image 463
Gooey Avatar asked Mar 25 '13 22:03

Gooey


1 Answers

            HttpPost httppost = new HttpPost(builder.getUrl());             httppost.setHeader(HTTP.CONTENT_TYPE,                     "application/x-www-form-urlencoded;charset=UTF-8");             // Add your data             httppost.setEntity(new UrlEncodedFormEntity(builder                     .getNameValuePairs(), "UTF-8"));              // Execute HTTP Post Request             HttpResponse response = httpclient.execute(httppost); 

Note: the builder just contains url and namevalue pairs.

like image 165
wtsang02 Avatar answered Sep 28 '22 02:09

wtsang02