HttpClient请求

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,Java)