0

我必须在类似于这样的 url 中发送数据:

http://webservices.fecth.es/school/message/sendmessage/id/myStringId/destination/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();

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

非常感谢

4

2 回答 2

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();
于 2013-02-28T14:32:21.437 回答
0

请使用以下代码检查状态

responsePOST.getStatusLine().getStatusCode()
于 2013-02-28T14:29:40.887 回答