用uri发送数据

时间:2013-02-28 14:22:54

标签: android post

我必须在类似于此的网址中发送数据:

http://webservices.fecth.es/school/message/sendmessage/ ID / myStringId / 目的地 / myStringDestination / MSG / myMessage

我在字符串中有必要的数据,但不是通过post方法发送,我已经测试了这段代码但不起作用:

String postURL = "http://webservices.fecth.es/school/message/sendmessage/";
HttpPost post = new HttpPost(postURL);
List<NameValuePair> param = new ArrayList<NameValuePair>();
param.add(new BasicNameValuePair("id", myId));
param.add(new BasicNameValuePair("destination", myStringDestination));
param.add(new BasicNameValuePair("msg", myMessage));

UrlEncodedFormEntity ent = new UrlEncodedFormEntity(param,HTTP.ISO_8859_1);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();

他们可以帮我解决问题吗?

非常感谢

2 个答案:

答案 0 :(得分:1)

试试这个:

StringBuffer postURL = new StringBuffer("http://webservices.fecth.es/school/message/sendmessage/");
postURL.append("id/");
postURL.append(URLEncoder.encode(myId, "UTF-8"));
postURL.append("/destination/");
postURL.append(URLEncoder.encode(myStringDestination, "UTF-8"));
postURL.append("/msg/");
postURL.append(URLEncoder.encode(myMessage, "UTF-8"));

HttpPost post = new HttpPost(postURL.toString());
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();

答案 1 :(得分:0)

请查看状态 以下代码

responsePOST.getStatusLine().getStatusCode()