Package Java-get-post Request Method

Source: Internet
Author: User

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 (Get content returned by 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 MD5 encryption algorithm
* @Title: Judgetoken
* @Description: TODO (here is a word describing the effect of this method)
* @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 Request
* @Title: Getrestcontent_get
* @Description: TODO (here is a word describing the effect of this method)
* @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 ();
}
}

Package Java-get-post Request Method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.