私はこのコードを持っています
public static String methodPost(final String url, final String dataToPost) throws ClientProtocolException,
IOException, IllegalStateException, Exception {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
StringEntity se = new StringEntity(dataToPost);
se.setContentEncoding("UTF-8");
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httpPost.setEntity(se);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
return streamToString(httpEntity.getContent());
}
私はこれを IPHONE に投稿し、完璧に動作します:
@"{\"var1\":\"Value1\"}{\"var2\":[{\"item1\":\"1\"},{\"item1\":\"Value2\"}]}"
ANDROIDにも投稿すると。
Response return HTTP 1 400
例:
methodPost(url, "{\"var1\":\"Value1\"}{\"var2\":[{\"item1\":\"1\"},{\"item1\":\"Value2\"}]}");
しかし、私はこれを投稿します
methodPost(url, "{\"var1\":\"Value1\"}{\"var2\":\"Value2\"}");
これは、「[]」を使用した場合にのみ完全に機能します。エラーが発生しました
私の英語でごめんなさい:)