概要:作为java开发技术人员,常常需要远程调用post,get请求,根据应该场景,请求格式也在变化。代码如下:
一.Http发起Post请求
(1)map的数据格式
public static String doPost(String url, Map<String, Object> param) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建参数列表
if (param != null) {
List<NameValuePair> paramList = new ArrayList<NameValuePair>();
for (String key : param.keySet()) {
Object value = param.get(key);
if(value!=null){
paramList.add(new B