使用 HttpUtil 调用 接口
来源:互联网 发布:查看linux oracle监听 编辑:程序博客网 时间:2024/06/05 23:51
下面是一个简单的http 请求demo:
package http;import java.io.IOException;import java.util.ArrayList;import java.util.List;import org.apache.http.HttpEntity;import org.apache.http.NameValuePair;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.CloseableHttpResponse;import org.apache.http.client.methods.HttpPost;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.HttpClients;import org.apache.http.message.BasicNameValuePair;import org.apache.http.util.EntityUtils;/** * 简单httpUtil * @author WWP * @date 2016-11-23 下午8:45:41 */public class HttpUtil { public static void executePost(String phone){ String url = "urladdress"; CloseableHttpClient client = null; HttpPost post = null; CloseableHttpResponse response = null; HttpEntity entity = null; UrlEncodedFormEntity uefEntity = null; try { client = HttpClients.custom().build(); post = new HttpPost(url); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("phone", phone)); uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8"); post.setEntity(uefEntity); try { response = client.execute(post); entity = response.getEntity(); System.out.println(EntityUtils.toString(entity)); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { response.close(); } } catch (Exception e) { e.printStackTrace(); } finally { try { client.close(); } catch (IOException e) { e.printStackTrace(); } } }}
0 0
- 使用 HttpUtil 调用 接口
- httpUtil使用
- Silverlight HttpUtil 封装Post调用
- HttpUtil
- HttpUtil
- httputil
- HttpUtil
- HttpUtil
- HttpUtil
- HttpUtil
- HttpUtil
- HttpUtil
- HttpUtil
- HttpUtil
- httpUtil
- HttpUtil
- HttpUtil
- HttpUtil
- linux压缩解压命令
- Ubuntu14.04 修改MAC地址-永久(临时)修改 Linux
- ORA-00845: MEMORY_TARGET not supported on this system
- NYOJ456 邮票分你一半(转化为01背包)
- 4412 android系统去掉和添加apk
- 使用 HttpUtil 调用 接口
- ural 1100. Final Standings -排序
- DWZ 学习
- node.js Buffer对象(模块详解)
- 【Codeforces 729 C Road to Cinema】 + 二分
- PLSQL Developer中文显示乱码
- Postman工具——请求与响应
- 解决MAC上使用Jenkins各种命令找不到的问题
- 干掉360的方法-Windows7