public void sendHttpRequest(){
HttpResponse response = null;
String url = "XXXXX";
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
//设置请求头
httpPost.setHeader("Content-Type”,“application/json”);
httpPost.setHeader("connection","Keep-Alive");
httpPost.setHeader("User-Agent","XXX");
StringEntity postEntity = new StringEntity(数据);
postEntity.setContentEnding("utf-8");
postEntity.setContentType("application/json");
//装填数据
httpPost.setEntity(postEntity);
respnse = httpClient.execute(httpPost);
//获取状态码
int statusCode = response.getStatusLine().getStatusCode();
}
HttpClient请求
最新推荐文章于 2024-01-14 12:47:40 发布