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 convert long Link into Sina short Link API Interface with PHP

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "PHP how to transform long links into Sina short links API interface", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to achieve PHP long links into Sina short links API interface" it!

Interface address

Sina short URL interface address:

Http://www.sinadwz.cn/sina.php?url_long=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!

At this point, I believe that everyone on the "PHP how to achieve long links into Sina short links API interface" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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