Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Sina short URL is generated online, and the official api interface is obtained.

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Recently, Sina Weibo Technology Center banned most of the keys used to generate short URLs: app_key, which led to the paralysis of the third-party short link generation service. The reason why Sina does this is to completely peel the short links from the Weibo platform, and to this end, it has specially set up a t.cn short chain generation platform for everyone to generate short chains free of charge.

Interface address: http://sina-t.cn/api?link=http://baidu.com

Instructions for use:

Replace the "http://baidu.com"" in the api interface address with the URL that needs to be shortened, and then copy it directly to the browser to open it.

Demo of PHP call:

$url = 'http://www.baidu.com';$api_url =' http://sina-t.cn/api?link=http://www.baidu.com;$short_url = file_get_contents ($api_url); echo $short_url

Demo of JAVA call:

Public static void main (String path []) throws Exception {URL u = new URL ("http://sina-t.cn/api?link=http://www.baidu.com");InputStream in = u.openStream (); ByteArrayOutputStream out = new ByteArrayOutputStream (); try {byte buf [] = new byte [1024]; int read = 0X while (read = in .read (buf)) > 0) {out.write (buf, 0, read);}} finally {if (in! = null) {in .close () }} byte b [] = out.toByteArray (); System.out.println (new String (b, "utf-8"));}

Demo of Python call:

Import urllib, urllib2, syshost = 'http://sina-t.cn'path =' api'method = 'GET'querys =' l=http%3A%2F%2Fwww.baidu.com'bodys = {} url = host + path +'?'+ querysrequest = urllib2.Request (url) response = urllib2.urlopen (request) content = response.read () if (content): print (content)

Note:

When ① calls the api interface, simply replace "http://www.baidu.com"" with a long URL that needs to be shortened.

The ② interface supports the url parameter. When the & symbol appears in the url, use% 26 instead (or use the url encoding format), otherwise the parameter may be lost.

③ must start with http (s): / / when filling in url, otherwise the resulting short URL may not be able to access the original website.

④ mentioned above several url.cn short URL api interface, after testing is relatively stable, feel good to remember to collect, so as not to lose.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report