【发布时间】:2014-03-26 21:47:12
【问题描述】:
我正在尝试在我的 android 应用程序中使用 http post 方法发布一些 json 数据,但是我似乎无法让它工作,字符串构建良好,如果我使用 google chrome addon 高级休息客户端进行测试,它就可以工作。我不是 JSON 最强的,因此为什么它是一个字符串而不是 JSON 对象。 Post 请求不执行。提前致谢
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/bulkClassifyJson?appid=matt-43@hotmail.com");
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());
【问题讨论】:
-
你的问题到底是什么?
-
在您使用时设置内容类型。
-
它不执行post请求
标签: java json http post jsonobject