How http://t.cn Sina t.cn short URL short URL is opened in the application

Have you ever need to share a link, but the URL for so long, it looks more like a garbled? No need to worry, because there are very smart on-line service called URL shortener. These new services will create a short link and guide users who are connected by a short URL to access your garbled long. Now, you can share this link with anyone you are interested in, without worrying about interfering with your e-mail, SMS or micro-channel circle of friends.

I came here to teach you step by step how to speak their long links converted into Sina short link (T.cn) / Tencent short link (Url.cn)!

Online tutorials to generate a short URL

 

1, to copy the shortened URL. You can shorten any long URL length is not important. Simply highlight the URL address bar, then press Ctrl + C (Win) or Command + C (MAC) and copy it to the clipboard.

Technical Picture

2, open Qingque assistant ( http://www.qqdwz.cn ) URL shortening services provided. Sina Web site provides a short link (T.cn) / Tencent short link (Url.cn) 2 Two Short link format!

 

3, it will be shortened to shorten the URL is pasted in the field. Put your cursor on the clipboard Web site, and then paste the URL copied. Ctrl + V (Win) command + V (MAC). Click on the "Generate" button. All sites have a shorter URL field next to the button, when clicked, it creates a shortened URL for you. Your new shortened URL will be displayed. Save yourself the shortened links on it!

Short URL Interface Application Tutorial

1. Click on the register button, fill in their account password. Click to register!

Technical Picture

2, fill in your account password. Click to register!

3, move the mouse to the user at the top right, click on the individual centers!

4, the personal Key Center you can see our API interface. Save Our Key, we can use the API interface to generate short links!

Calling code

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://www.qqdwz.cn/sina.php?url_long=http://www.baidu.com;
$short_url = file_get_contents($api_url);
echo $short_url;

JAVA调用演示:

public static void main(String path[]) throws Exception {
URL u = new URL("http://www.qqdwz.cn/sina.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调用演示:

import urllib, urllib2, sys
host = ‘http://www.qqdwz.cn‘
path = ‘sina.php?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)

Precautions:

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

② interface supports url parameters, when the & symbol appears in the url, use 26% instead of (or use the url encoding format), or 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 url.cn short URL api interfaces ④ mentioned above, the tests 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 url coding!

② 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.

Short URL generated is valid ③ how long? There is no limit visits?

A: The short URL is generated url permanent and effective, and there is no limit clicks, you can use any!



Guess you like

Origin blog.51cto.com/14764288/2481241