0

次のような URL でデータを送信する必要があります。

http://webservices.fecth.es/school/message/sendmessage/ id / myStringId /宛先/ myStringDestination / msg / myMessage

私は文字列に必要なデータを持っていますが、ポストメソッドを介してこれを送信するのではなく、このコードをテストしましたが機能しません:

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 に答える