分享一个在线腾讯短链(url.cn)生成工具,支持在线生成及接口方式生成。

腾讯短链(url.cn)在线工具

短链生成在线工具:https://www.sojson.com/dwz.html

腾讯短链(url.cn)接口

接口地址:http://shorturl.8446666.sojson.com/qq/shorturl?url=https://www.jsjiami.com

传参方式:url = 要生成的短链,带参数请urlencode编码一下。

收费方式:免费,不限制次数,但是限制频率。

python 请求腾讯短链接口代码示例

import json, urllib
from urllib import urlencode

url = "http://shorturl.8446666.sojson.com/qq/shorturl"
params = {
	"url": "https://www.jsjiami.com",  # 需要生成的长链
}
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 = "https://www.jsjiami.com";
		method =  new GetMethod("http://shorturl.8446666.sojson.com/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/20100101 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;
	}
}

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐