public static String sendHttpRequestByPost(final String address,String encode,MatterReflectDTO dto){
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供安州網(wǎng)站建設(shè)、安州做網(wǎng)站、安州網(wǎng)站設(shè)計(jì)、安州網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、安州企業(yè)網(wǎng)站模板建站服務(wù),十多年安州做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
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("請(qǐng)求結(jié)果:"+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;
}
服務(wù)器端使用的是.net暫時(shí)就不貼出來了,需要注意的是并不是通過參數(shù)傳遞的。