HttpPost 経由でデータを送信しようとしていますが、空になります。メソッドと HttpGET 部分が正常に機能している場合は、以下を参照してください。しかし、投稿本文にデータを追加して送信しようとすると、エラーは発生せず、Logcat (+ 反対側の REST Web サービス) は投稿データが空であることを示します。
public void sendPhoto(View v) {
final String kookojaUrlGet = "http://localhost/getData";
final String kookojaUrlPost = "http://localhost/postData";
new Thread(new Runnable() {
@Override
public void run() {
HttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse getResponse = httpClient.execute(new HttpGet(kookojaUrlGet));
String returnedStuff = EntityUtils.toString(getResponse.getEntity());
Log.d("debug","http get returned " + returnedStuff);
JSONObject jsonGet = new JSONObject(returnedStuff);
int xxxTime = jsonGet.getInt("timestamp");
String xxxNone = jsonGet.getString("nonce");
String xxxApp = jsonGet.getString("appName");
String xxxCID = jsonGet.getString("csrfToken");
Log.d("debug","json was " + xxxTime + " " + xxxNone + " " + xxxApp + " " + xxxCID);
JSONObject c = new JSONObject();
c.put("_username","xxx@gmail.com");
c.put("_password","123");
c.put("_timestamp", xxxTime);
c.put("_nonce", xxxNone);
c.put("_appName", xxxApp);
c.put("CID", xxxCID);
c.put("body", photoPost);
c.put("long", photoLong);
c.put("lat", photoLat);
StringEntity sendStuff = new StringEntity(c.toString());
HttpPost xxxPost = new HttpPost(kookojaUrlPost);
xxxPost.setHeader("Accept", "application/json");
xxxPost.setHeader("Content-type", "application/json");
xxxPost.setHeader("Accept-Encoding", "gzip");
xxxPost.setEntity(sendStuff);
HttpResponse postResponse = httpClient.execute(xxxPost);
String postText = EntityUtils.toString(postResponse.getEntity());
Log.d("debug", "rest post response was " + postText);
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
}).start();
}
任意の助けをいただければ幸いです。