HttpClient client = buildHttpClient(false); try{ // http://v.juhe.cn/sms/send?mobile=手机号码&tpl_id=短信模板ID&tpl_value=%23code%23%3D654654&key= HttpPost postMethod = buildHttpPost(url, params); HttpResponse response = client.execute(postMethod); assertStatus(response); HttpEntity entity = response.getEntity(); String returnStr = EntityUtils.toString(entity, CONTENT_CHARSET); return returnStr; }catch(URISyntaxException ue){ ue.printStackTrace(); }catch(ClientProtocolException ce){ ce.printStackTrace(); }catch(IOException ie){ ie.printStackTrace(); } return null; }
/** * 创建HttpClient * 2017年4月25日下午2:46:05 */ public static HttpClient buildHttpClient(boolean isMultiThread) { CloseableHttpClient client; if (isMultiThread) { client = HttpClientBuilder.create().setConnectionManager(new PoolingHttpClientConnectionManager()).build(); }else { client = HttpClientBuilder.create().build(); } // 设置代理服务器地址和端口 // client.getHostConfiguration().setProxy("proxy_host_addr",proxy_port); return client; }