I was looking information about how I can send information using HttpPost method on android, and I always see this:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(posturl);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Name","Var1"));
params.add(new BasicNameValuePair("Name2","Var2"));
httppost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse resp = httpclient.execute(httppost);
HttpEntity ent = resp.getEntity();
The problem is that I cant do that, because I have to connect to a resource that receive a String with XML format.
Any idea about how can I send only the String without using a List<nameValuePair>
Have you tried using StringEntity? Above code can be updated to use StringEntity
, Following is the resulting code:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(posturl);
httppost.setEntity(new StringEntity("your string"));
HttpResponse resp = httpclient.execute(httppost);
HttpEntity ent = resp.getEntity();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With