How to call Sina official short URL via Java API interface Short URL shortening feature

    Sina official for a long time before providing long links into short links T.CN the API, you can put long links into short links t.cn/xxx this format. But in September of this year, Sina due to the adjustment of policy, the previous interface to shut down! !

Now lead to many small partners are unable to use short links Sina, and today I'll share with you a tutorial how to use Sina short URL JAVA language call:


interface address

Sina Short URL API interface:

http://www.sinadwz.cn/sina.php?url_long=http://www.baidu.com  


Interface Description

The "upper short URL Sina api interface http://www.baidu.com " can be replaced with a long link to be generated


Document Interface

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"));
    }

PHP calling code:

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

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)


This article comes from the waves fox Short URL: http: //www.sinadwz.cn/bavfsy.html please indicate the source

Guess you like

Origin www.cnblogs.com/fdagfd/p/11994890.html