您好,登錄后才能下訂單哦!
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暫時就不貼出來了,需要注意的是并不是通過參數傳遞的。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。