ローカル マシンで tomcat サーブレットを実行し、サーブレットへの投稿要求を行うアプリを使用して Android エミュレーターを実行しています。POST のコードは次のとおりです (例外などは除きます)。
String strUrl = "http://10.0.2.2:8080/DeviceDiscoveryServer/server/devices/";
Device device = Device.getUniqueInstance();
urlParameters += URLEncoder.encode("user", "UTF-8") + "=" + URLEncoder.encode(device.getUser(), "UTF-8");
urlParameters += "&" + URLEncoder.encode("port", "UTF-8") + "=" + URLEncoder.encode(new Integer(Device.PORT).toString(), "UTF-8");
urlParameters += "&" + URLEncoder.encode("address", "UTF-8") + "=" + URLEncoder.encode(device.getAddress().getHostAddress(), "UTF-8");
URL url = new URL(strUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(urlParameters);
wr.flush();
wr.close();
このコードが実行されるたびに、サーブレットは呼び出されません。ただし、リクエストのタイプを「GET」に変更し、出力ストリームに何も書き込まないと、サーブレットが呼び出され、すべて正常に動作します。POST を正しく行っていないだけですか、それとも他のエラーがありますか?