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

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

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

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!

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

Development

Wechat

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

12
Report