In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how PHP and Python call Sina short URL API interface". In daily operation, I believe many people have doubts about how PHP and Python call Sina short URL API interface. Xiaobian consulted all kinds of materials and sorted out simple and easy to use operation methods. I hope to answer your doubts about "how PHP and Python call Sina short URL API interface"! Next, please follow the small series to learn together!
Instructions for use:
Replace "http://www.baidu.com" in the api interface address with a shortened URL, and then copy it directly to the browser to open it.
PHP call demo:
$url = 'http://www.baidu.com';$api_url = 'http://qingmeidwz.cn/shorten.php? url_long=http://www.baidu.com';$short_url = file_get_contents($api_url);echo $short_url;
JAVA call demo:
public static void main(String path[]) throws Exception {URL u = new URL("http://qingmeidwz.cn/shorten.php? url_long=http://www.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 calls demo:
import urllib, urllib2, syshost = 'http://qingmeidwz.cn/'path = 'shorten.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)
Notes:
① When calling the api interface, just replace "http://www.baidu.com" with a long URL that needs to be shortened.
② The interface supports url parameters. When the & symbol appears in url, please replace it with %26, otherwise the parameters may be lost.
③ When filling in the url, it must start with http(s)://, otherwise it may cause the short URL generated to be unable to access the original website.
④ The t.cn short URL api interface above is very stable after testing. I think it's good to remember to collect it so as not to lose it.
Frequently Asked Questions:
① Long link conversion, why are the parameters at the end lost?
Answer: Because url contains special characters, you need to use UTF8 encoding format to encode url.
② Interface does not return results, what is the situation?
A: Sometimes there is a delay in the data returned by the interface. If the delay does not return, it will prompt that the generation fails; or the original link is blocked.
3 How long is the generated t.cn short URL valid? Is there a limit on the number of visits?
A: The generated t.cn short URL is permanently valid, and there is no limit on the number of clicks. It can be used arbitrarily.
At this point, the study of "how PHP and Python call Sina short URL API interface" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.