How to call Sina short link / Tencent short link API interface
This article mainly shows you "how to use Sina short links / Tencent short links API interface", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use Sina short links / Tencent short links API interface" this article.
Interface address
Short URL interface address:
1. Interface address: http://www.wx-url.cn/sina.php?url_long=http://www.baidu.com
two。 Interface address: http://dogdwz.cn/tcnjson?url=http://www.baidu.com
3. Interface address: http://www.sina-url.cn/xinlang?url=http://www.baidu.com
4. Interface address: http://www.wx-dwz.cn/tcnurl?url=https://www.baidu.com
5. Interface address: http://mhdwz.cn/mhsina?url=http://www.baidu.com
6. Interface address: http://maiyurl.cn/weibourl?url=http://www.baidu.com
Note: replace the link in the red part of the api interface of the above short URL with a long connection that needs to be shortened!
Interface document
PHP call code:
$url = 'http://www.baidu.com';$api_url =' .urlencode ($url); $short_url = file_get_contents ($api_url); echo $short_url
Other language call documents
JAVA call code:
Public static void main (String path []) throws Exception {URL u = new URL ("http%3A%2F%2Fwww.baidu.com"); InputStream in = u.openStream (); ByteArrayOutputStream out = new ByteArrayOutputStream (); try {byte buf [] = new byte [1024]; int read = 0; 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"));}
Python call code:
Import urllib, urllib2, sys host =''path =' 'method =' GET' querys = 'http%3A%2F%2Fwww.baidu.com' bodys = {} url = host + path +'?'+ querys request = urllib2.Request (url) response = urllib2.urlopen (request) content = response.read () if (content): print (content) Note:
1. When using the api API, you only need to replace the link after URL= with the long link that needs to be shortened on your own side.
2. The API supports parameter passing. When the & symbol appears in the link, use% 26 instead (or use url coding), otherwise the parameters will be lost.
3. When filling in the link, you must use the http (s): / / protocol, otherwise the API interface will not be able to generate short links!
The above is all the content of this article "how to call Sina short link / Tencent short link API interface". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!