Recommended several of the most recent official Sina api interface to a short URL

API interface

Provides long links into short links API Sina before long, we can put a long link into t.cn/xxx short links in this format. But in September of this year, Sina due to the adjustment of policy, the previous interface to shut down! !

Many small partners have encountered confusion Sina short link to it, some of my friends have seen piecemeal approach online Sina short link, and did not completely understand how Sina short links are solved, Xiao Bian today to prepare simple solutions way, we only need to follow the tutorial to operate

So today I gave you recommend a few short links Sina API interface we're using now, and I hope you can help to you.

Sina short URL API interface (available pro-test)

1. Interface Address:  http://www.wx-url.cn/sina.php?url_long=http://www.baidu.com

2. Interface Address:  http://dogdwz.cn/tcnjson?url=http://www.baidu.com

3. Interface Address:  http://www.sina-url.cn/xinlang?url= http://www.baidu.com

4. Interface Address: http://www.wx-dwz.cn/tcnurl?url=https://www.baidu.com

5. Interface Address: http://mhdwz.cn/mhsina?url=http://www.baidu.com

6. Interface Address: http://maiyurl.cn/weibourl?url=http://www.baidu.com


Sina short URL API instructions

The "http://www.baidu.com" short URL above Sina api interface section with the long link you need to generate a short URL corresponding Sina!


Sina short URL interface documentation

PHP calling code:

$url = 'http://www.baidu.com';
$api_url = ''.urlencode($url);
$short_url = file_get_contents($api_url);
echo $short_url;

JAVA calling 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 calling 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)

Guess you like

Origin www.cnblogs.com/ss11223/p/11946791.html