public static String sendHttpRequestByPost(final String address,String encode,MatterReflectDTO dto){
创新互联专业为企业提供安州网站建设、安州做网站、安州网站设计、安州网站制作等企业网站建设、网页设计与制作、安州企业网站模板建站服务,十多年安州做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
String result = "";
DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(address);
String jsonString = dto.toString();
try {
StringEntity stringEntity = new StringEntity(new GsonBuilder().create().toJson(dto));
System.out.println(stringEntity.toString());
httpPost.setEntity(stringEntity);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader("Accept-Encoding", "gzip");
HttpResponse httpResponse = defaultHttpClient.execute(httpPost);
System.out.println("请求结果:"+httpResponse.getStatusLine().getStatusCode());
int code = httpResponse.getStatusLine().getStatusCode();
if(code ==200){
InputStream is = httpResponse.getEntity().getContent();
result = "true";
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
服务器端使用的是.net暂时就不贴出来了,需要注意的是并不是通过参数传递的。
网站名称:Android访问WEBAPI,传递json
网站网址:https://www.cdcxhl.com/article40/godjho.html
成都网站建设公司_创新互联,为您提供做网站、外贸网站建设、品牌网站制作、虚拟主机、关键词优化、网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联