java能用微信吗_java微信分享功能(拿过来直接可以用)

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参数)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值