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();
    }
    }

  • 相关阅读:
    POJ2553 The Bottom of a Graph 强连通分量+缩点
    销售里面最猛的还是传销模式
    **Error 1 The type 'System.Web.Compilation.WCFBuildProvider' is ambiguous: it could come from assembly 'C:\Windows\Micro
    自定义Proxy 来做 rest wcf的客户端 与 WebChannelFactory<>的bug
    你知道吗string GetHashCode方法跟环境是有关的吗?
    查找默认的一个实体如果没有就找第一个的写法
    如何解决WCF REST 中 WebFaultException抛出的异常客户端WebChannelFactory无法处理的问题
    Google 的统计或将导致 IE7已终止操作
    类别进行排序的一个简单分析
    抢夺客户的战争
  • 原文地址:https://www.cnblogs.com/liuying1995/p/5729164.html
Copyright © 2011-2022 走看看