• 封装java-get-post请求方式


    package com.ecar.eoc.content.platform.utils;

    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;

    import org.apache.log4j.Logger;

    import com.ecar.commons.cmf.util.PropertiesUtil;
    import com.ecar.rtplt.component.web.HttpRequester;
    import com.ecar.rtplt.component.web.HttpResponser;

    public class RestUtil
    {
    private static Logger logger = Logger.getLogger(RestUtil.class);
    /**
    *
    * @Title: getRestContent
    * @Description: TODO(获取rest返回的内容)
    * @param url
    * @param map
    * @return
    * @throws IOException
    * @author yuqidi
    * @date 2015-4-27 下午07:30:03
    * @version V1.0
    */
    public static String getRestContent(String url, Map<String, String> map) throws IOException
    {
    HttpRequester request = new HttpRequester();
    request.setDefaultContentEncoding("utf-8");
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("Content-type", "application/x-www-form-urlencoded; charset=utf-8");

    if (logger.isInfoEnabled())
    {
    logger.info(new StringBuffer("url=").append(url).append(new org.json.JSONObject(map)));
    }

    HttpResponser responser = request.sendPost(url, map, properties);

    return responser.getContent();
    }
    /**
    * base 64 MD5 加密算法
    * @Title: judgeToken
    * @Description: TODO(这里用一句话描述这个方法的作用)
    * @param: @param map
    * @param: @param appKey
    * @param: @param nonce
    * @param: @param timestamp
    * @param: @param sign
    * @param: @return
    * @return: Boolean
    * @throws
    * @author ecar
    * @Date 2016-5-20 上午11:10:46
    */
    public static Boolean judgeToken(Map<Object, Object> map, String appKey, String nonce, Long timestamp, String sign)
    {

    String appSrect = PropertiesUtil.getValueString("ep023_SECRET_KEY", "D90C8B17FB4FBD6442FDEC51C735E91C");
    return AuthSigHelpter.authSig(appKey, appSrect, timestamp, nonce, map, sign);
    }

    /**
    * get请求
    * @Title: getRestContent_get
    * @Description: TODO(这里用一句话描述这个方法的作用)
    * @param: @param url
    * @param: @param map
    * @param: @return
    * @param: @throws IOException
    * @return: String
    * @throws
    * @author ecar
    * @Date 2016-7-11 下午07:32:02
    */
    public static String getRestContent_get(String url) throws IOException
    {
    HttpRequester request = new HttpRequester();
    request.setDefaultContentEncoding("utf-8");
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("Content-type", "application/x-www-form-urlencoded; charset=utf-8");

    if (logger.isInfoEnabled())
    {
    logger.info(new StringBuffer("url=").append(url));
    }

    HttpResponser responser = request.sendGet(url);

    return responser.getContent();
    }
    }

  • 相关阅读:
    20170421 F110 常见问题
    BAPI_ACC_DOCUMENT_POST 解决原因代码输入问题-利用BADI
    ABAP f4帮助输入多个值
    002 MIRO发票校验采购订单项目科目分配类别检查增强-20150819
    001infor record 计划时间取值增强-20150622
    003 F-47创建预付定金请求检查增强-20150819.docx
    整理开源协议问题 GPL APACHE
    拆我的跨界手环
    ThinkPHP 的一个神秘版本 ThinkPHP 1.2
    关于 Vue 方法前面的美元符号
  • 原文地址:https://www.cnblogs.com/liuying1995/p/5729164.html
Copyright © 2020-2023  润新知