zoukankan      html  css  js  c++  java
  • 封装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();
    }
    }

  • 相关阅读:
    服务端渲染
    node基础
    vue不同组件间的通信
    mui底部导航栏
    在mui中引入自定义的字体图标
    axios的使用
    vue多视图
    多元线性回归:波士顿房价预测问题TesnsorFlow实战
    MNIST手写数字识别:分类应用入门(实践篇)
    7-3 java高级 22_19寻找最大块的问题 (20 分)
  • 原文地址:https://www.cnblogs.com/liuying1995/p/5729164.html
Copyright © 2011-2022 走看看