zoukankan      html  css  js  c++  java
  • 将参数拼接在请求地址后面发送post请求

    发送示例: 
    http://IP:port/baidu.com?action=2&yydm=kfcs&paytype=3&notifyUrl=1&czyh=wnpay&outSignNo=1  //post请求
    
    public class DoPostUtils {
    
        public static String doPost(String url, Map<String, String> 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<>();
                    for (String key : param.keySet()) {
                        paramList.add(new BasicNameValuePair(key, param.get(key)));
                    }
                    // 模拟表单
                    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList,"utf-8");
    
                    httpPost.setEntity(entity);
                }
                // 执行http请求
                response = httpClient.execute(httpPost);
    
                resultString = EntityUtils.toString(response.getEntity(), "utf-8");
                System.out.println( resultString);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    response.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
    
            return resultString;
        }
    
    }
  • 相关阅读:
    .Net Core 微服务学习一
    微服务学习一
    软件开发基本接口学习二
    浏览器根对象window之操作方法
    浏览器根对象window之caches
    Angular面试题三
    浏览器根对象window之performance
    Angular面试题二
    浏览器根对象window之screen
    浏览器根对象window之history
  • 原文地址:https://www.cnblogs.com/yydxh/p/13253121.html
Copyright © 2011-2022 走看看