我想在我的android应用程序内使用http post方法发布一些json数据,但是我似乎无法得到它的工作,字符串是建设良好,它的工作原理,如果我测试使用谷歌Chrome插件高级休息客户端。我不是JSON最强的,因此它是一个字符串而不是JSON对象。邮政请求不会执行。在此先感谢HTTP post JSON java
String json = "{\"data\": [";
for (String tweet : tweetContent)
{
json = json + "{\"text\": \"" + tweet + "\", \"query\": \"" + SearchTerm + "\", \"topic\": \"movies\"},";
}
json = json.substring(0, json.length() - 1);
json = json + "]}";
Log.i("matt", json);
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.sentiment140.com/api/[email protected]");
StringEntity entity = new StringEntity(json, HTTP.UTF_8);
httppost.setEntity(entity);
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String responseBody = EntityUtils.toString(response.getEntity());
Log.i(LOG_TAG, responseBody);
sentiments.add(responseBody.toString());
究竟是什么问题? –
设置内容类型。 –
它不执行发布请求 – user3456401