Android and HTTP POST

Hi Guyz,

In Last Post Code Snipped was for the GET Request Method from any provided URL You can find it here.

Now, Let’s POST something to some address, below is code for it

private String postData(String URL, String xml) throws ClientProtocolException, IOException
String strRepsonse = “”;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL); //url to post information or any one you have
ByteArrayEntity bytes = new ByteArrayEntity(xml.getBytes());
bytes.setContentType(“application/xml”); // set approporiate content type
httppost.setEntity(bytes); //set entity type to post
HttpResponse response = httpclient.execute(httppost); //import line of code
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
BufferedReader rd = new BufferedReader(new
String line = “”;
while ((line = rd.readLine()) != null) {
strRepsonse += line;
return strRepsonse;

If you’re using local address than you need to use IP Address of the server like