分享一个在线腾讯短链()生成工具,支持在线生成及接口方式生成。
腾讯短链()在线工具
短链生成在线工具:/dwz.html
腾讯短链()接口
接口地址:http://shorturl./qq/shorturl?url=
传参方式:url = 要生成的短链,带参数请urlencode编码一下。
收费方式:免费,不限制次数,但是限制频率。
python 请求腾讯短链接口代码示例
import json, urllibfrom urllib import urlencodeurl = "http://shorturl./qq/shorturl"params = {"url": "", # 需要生成的长链}params = urlencode(params)f = urllib.urlopen(url, params)content = f.read()res = json.loads(content)if res:print(res)else:print("请求异常")
Java 请求腾讯短链接口代码示例
public static void main(String[] args) {HttpMethodBase method = null;HttpClient client = null;try {String url = "";method = new GetMethod("http://shorturl./qq/shorturl?url=" + url);client = new HttpClient();client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8");//关闭链接client.getParams().setParameter("Connection", "close");//请求超时client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 2000);//读取超时client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 2000);method.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/0101 Firefox/42.0");method.setRequestHeader("Connection", "close");int status = client.executeMethod(method);if(status != HttpStatus.SC_OK){System.out.println("请求失败");}String content = method.getResponseBodyAsString();System.out.println("请求返回:"+content);} catch (Exception e) {}finally{client = null;if(null != method)method.releaseConnection();method = null;}}