How Sina short link generation? Sina t.cn short link interface to share!

Sharing a short URL t.cn latest generation api interface to quickly generate ultrashort t.cn link interface normal call, you can feel good about the collection.

Sina api interface to Short URL :

http://qingmeidwz.cn/shorten.json?url_long=http://www.baidu.com

Instructions for use:

The api interface address in the " http://www.baidu.com" replaced the need to shorten the URL, then copy direct access to the browser to open .

PHP call demo:

URL = $ ' http://www.baidu.com ';
$ api_url = ' http://qingmeidwz.cn/shorten.json?url_long=http://www.baidu.com ';
$ SHORT_URL = file_get_contents ($ api_url);
echo $ short_url;
JAVA call presentation:

public static void main(String path[]) throws Exception {<br/>URL u = new URL("http://qingmeidwz.cn/shorten.json?url_long=http://www.baidu.com");<br/>InputStream in = u.openStream();<br/>ByteArrayOutputStream out = new ByteArrayOutputStream();<br/>try {<br/>byte buf[] = new byte[1024];<br/>int read = 0;<br/>while ((read = in .read(buf)) &gt; 0) {<br/>out.write(buf, 0, read);<br/>}<br/>} finally {<br/>if ( in != null) {<br/>in .close();<br/>}<br/>}<br/>byte b[] = out.toByteArray();<br/>System.out.println(new String(b, "utf-8"));<br/>}<br/>
Python calls the demo:

import urllib, urllib2, sys
host = 'http://qingmeidwz.cn/'
path = 'shorten.json?url_long='
method = 'GET'
querys = 'url=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)
注意事项:

① When calling api interface simply " http://www.baidu.com" replaced the need to shorten the length of the URL .

② interface supports url parameters, when the & symbol appears in the url, use instead of 26%, otherwise the parameters may be lost.

When ③ fill url, must be based on http (s): // at the beginning, it may cause a short URL to give birth can not access the original site.

Several mentioned above t.cn ④ short URL api interface has been tested and are relatively stable, it felt good to remember collection, to avoid loss.

common problem:

① long link translation parameters why the end is lost?

A: Because the url contains special characters, you need to use UTF8 encoding format, the encoded url

② interface does not return a result, what is the situation?

A: Sometimes the interface returns the data will be delayed, the delay did not return will be prompted to generate a failure; or because the original link was closed.

How long t.cn ③ generated short URL is valid? There is no limit visits?

A: The short URL is generated t.cn permanent and effective, and there is no limit clicks, you can use any

Guess you like

Origin blog.51cto.com/14645761/2484150
Recommended