String uriAPI = "http://192.168.11.108:2492/json/SendMessage/";
HttpPost httpRequest =new HttpPost(uriAPI);
try{
StringEntity myEntity = new StringEntity("abc");
httpRequest.setEntity(myEntity);
HttpResponse httpResponse=new DefaultHttpClient().execute(httpRequest);
//若状态码为200 ok
if(httpResponse.getStatusLine().getStatusCode()==200){
String strResult=EntityUtils.toString(httpResponse.getEntity());
}
else
{
Log.v("tag", "Error Response"+httpResponse.getStatusLine().toString() );
}
}catch(ClientProtocolException e){
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
主要实设置myEntity 的内容设置为要上传的string替换掉原来的Entity 即可。
StringEntity myEntity = new StringEntity("abc");
httpRequest.setEntity(myEntity);