我正在尝试向服务器发送id,在该服务器上将针对该id生成响应,我对该服务器的id是正常的,但响应是空数据数组。
try {
httppost.setEntity(new StringEntity(vol_id));
Log.e("vol", vol_id);
HttpResponse resp = httpclient.execute(httppost);
HttpEntity ent = resp.getEntity();
getResult = EntityUtils.toString(ent);
savePreferences("asset_data", getResult);
} catch (IOException e) {
e.printStackTrace();
}
答案 0 :(得分:0)
Try this code with the concept and jar file of multipart entitiy to post string:
Make http request some like as you know:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.tumblr.com/api/write");
Then critical requirement is this to post string over id defined in server:
try {
MultipartEntity entity = new MultipartEntity();
entity.addPart("type", new StringBody("photo")); //photo is id for string defined to post
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
} catch (IOException e) {
}