java post加密_封装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 map) throws IOException

{

HttpRequester request = new HttpRequester();

request.setDefaultContentEncoding("utf-8");

Map properties = new HashMap();

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 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 properties = new HashMap();

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

}

}

原文:http://www.cnblogs.com/liuying1995/p/5729164.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值