Android Java 環境で URL への POST の応答を取得しようとしています。
これが私のコードです:
try{
DefaultHttpClient httpClient = new DefaultHttpClient();
ResponseHandler <String> resonseHandler = new BasicResponseHandler();
HttpPost postMethod = new HttpPost("http://myurl.com/post.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
JSONObject jsonObject = new JSONObject();
jsonObject.put("data1", "OK");
jsonObject.put("data2", "OK2");
nameValuePairs.add(new BasicNameValuePair("jsonString", jsonObject.toString()));
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
String response = httpClient.execute(postMethod,resonseHandler);
System.out.println(response);
}
catch(Exception e)
{
System.out.println("DIED");
}
案の定、「DIED」が返されます。次のように変更System.out.println("DIED");
するとSystem.out.println(e.getMessage())
、アプリケーションがクラッシュします。
私は何を間違っていますか?