package cn.com.sinosoft.util;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.regex.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import redis.clients.jedis.Jedis;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import org.apache.log4j.Logger;
import org.junit.Test;
import com.alibaba.fastjson.JSONObject;
/**
* request信息
* @author
*
*/
public class CommonUtil {
private static Logger logger = Logger.getLogger(CommonUtil.class);
private static String appId = "";
private static String secret = "";
/*private static String appId = "";
private static String secret = "";*/
public static JSONObject getUrlInfo(String requestURL,String method,String json) throws Exception {
URL get_url = new URL(requestURL);
// 将url 以 open方法返回的urlConnection 连接强转为HttpURLConnection连接
// (标识一个url所引用的远程对象连接)
// 此时cnnection只是为一个连接对象,待连接中
HttpURLConnection httpURLConnection = (HttpURLConnection) get_url
.openConnection();
// 设置请求方式为post
httpURLConnection.setRequestMethod(method);
// 设置连接输出流为true,默认false (post 请求是以流的方式隐式的传递参数)
httpURLConnection.setDoOutput(true);
// 设置连接输入流为true
httpURLConnection.setDoInput(true);
// post请求缓存设为false
httpURLConnection.setUseCaches(false);
// 设置请求头里面的各个属性 (以下为设置内容的类型,设置为经过urlEncoded编码过的from参数)