发送的Andr​​oid字符串与HttpPost不使用namevaluepairs中 [英] Send a string on Android with HttpPost without using nameValuePairs

查看:160
本文介绍了发送的Andr​​oid字符串与HttpPost不使用namevaluepairs中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找,我怎么可以使用HttpPost Android上的方法来发送信息的信息,我总是看到以下内容:

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

问题是,我不能这样做,因为我有连接到接收字符串的XML格式的资源。

The problem is that I cant do that, because I have to connect to a resource that receive a String with XML format.

如何我只能发送字符串,而无需使用任何想法列表与LT;&的NameValuePair GT;

Any idea about how can I send only the String without using a List<nameValuePair>

推荐答案

您是否尝试过使用<一个href=\"http://developer.android.com/reference/org/apache/http/entity/StringEntity.html\">StringEntity?上述code可以更新为使用 StringEntity ,以下是得到的code:

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

这篇关于发送的Andr​​oid字符串与HttpPost不使用namevaluepairs中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆