zoukankan      html  css  js  c++  java
  • x-www-form-urlencoded请求封装

    <dependency>
       <groupId>commons-httpclient</groupId>
       <artifactId>commons-httpclient</artifactId>
       <version>3.1</version>
    </dependency>
        public static String postJsonMethodParamsEncode(String postURL,Map<String,String> destMap){
            log.info("postJsonMethodParamsEncode request postURL:{}",postURL);
            try {
                PostMethod postMethod = null;
                postMethod = new PostMethod(postURL) ;
                postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8") ;
                NameValuePair[] data = new NameValuePair[destMap.size()];
                int i = 0;
                for (String key : destMap.keySet()){
                    data[i] = new NameValuePair(key,destMap.get(key));
                    i++;
                }
    
                postMethod.setRequestBody(data);
                HttpClient httpClient = new HttpClient();
                int response = httpClient.executeMethod(postMethod);
                return postMethod.getResponseBodyAsString() ;
            } catch (Exception e) {
                log.error("请求异常:",e);
                throw new RuntimeException(e.getMessage());
            }
        }
  • 相关阅读:
    hdu5412CRB and Queries
    LCA rmq st model
    HDU 5348 MZL's endless loop
    2015多校联合训练赛 Training Contest 4 1008
    Bestcoder Tom and matrix
    TOJ 4105
    Codeforces D. Iahub and Xors
    Set 技巧之一
    1036: [ZJOI2008]树的统计Count
    一点点VIM
  • 原文地址:https://www.cnblogs.com/big-cut-cat/p/13534708.html
Copyright © 2011-2022 走看看