Webサービスを作成してAndroidから使用しようとしています。GET メソッドは動作していますが、POST メソッドを呼び出すことができません。
@Path("/dictionary")
public class DictionaryWebService {
private final static String ID = "id";
private final static String WORD = "palabra";
private final static String DESCRIPTION = "description";
.....
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public Word postNewWord(MultivaluedMap<String, String> newWord) {
Word dict;
String id = newWord.getFirst(ID);
String word = newWord.getFirst(WORD);
String description = newWord.getFirst(DESCRIPTION);
dict = new Word(id, word, description);
dictionary.putNewWord(dict);
System.out.println("New Word info: " + dict.toString());
return dict;
}
}
私のアンドロイドコードは次のとおりです。
@Override
public void onClick(View arg0) {
System.out.println("onClick!!!");
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost("http://10.0.2.2:8080/DictionaryWebService/rest/dictionary/");
post.setHeader("content-type", "application/json");
//Construimos el objeto cliente en formato JSON
JSONObject dato = new JSONObject();
try {
dato.put("id", txtId.getText().toString());
dato.put("palabra", txtWord.getText().toString());
dato.put("description", txtDescription.getText().toString());
StringEntity entity = new StringEntity(dato.toString());
post.setEntity(entity);
HttpResponse resp = httpClient.execute(post);
String respStr = EntityUtils.toString(resp.getEntity());
System.out.println("OKAY!");
.....
}
});
わかりませんが、Webサービスを実行できません、、、呼び出されていません。なにが問題ですか??誰かが私を助けることができますか?onclick メソッドはエラーなしで終了します。
ありがとうございました。