关于前端:2020年腾讯短链urlcn官方免费接口调用源码免费API接口调用

28次阅读

共计 1453 个字符,预计需要花费 4 分钟才能阅读完成。

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

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

腾讯短链(url.cn)接口

接口地址:http://shorturl.8446666.sojso…

传参形式: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;
    }
}

正文完
 0