Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use PHP to call api interface of Tencent short URL

Shulou Source: shulou.com Published: 2022-06-02 08:52:28 09月10日 Update

This article mainly introduces "how to use PHP to call Tencent short URL api interface". In daily operation, I believe many people have doubts about how to use PHP to call Tencent short URL api interface. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use PHP to call Tencent short URL api interface". Next, please follow the editor to study!

Interface 1: http://www.sinadwz.cn/url/dwz.php?url_long=http://www.baidu.com

Interface 2: http://maiyurl.cn/tengxurl?url_long=http://www.baidu.com

Interface 3: http://www.sina-url.cn/txdwz.php?url_long=http://www.baidu.com

Interface 4: http://www.qqdwz.cn/urlcn/api? url_long= http://www.baidu.com

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.

Demo of PHP call:

$url = 'http://www.baidu.com';$api_url =' http://www.qqdwz.cn/tcn/api?url_long=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://www.qqdwz.cn/tcn/api?url_long=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://www.qqdwz.cn' path = 'sina.php?url_long='method =' GET'querys = 'url=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), this is the end of the study on "how to use PHP to call the api interface of Tencent short URL" I hope I can solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Interface URL Tencent learning presentation parameters more website help practical next just the beginning article method format theory knowledge symbol article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Linux NVidia vpn MariaDB