這篇文章主要為大家展示了“如何利用調(diào)用新浪短鏈接/騰訊短鏈接API接口”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“如何利用調(diào)用新浪短鏈接/騰訊短鏈接API接口”這篇文章吧。
短網(wǎng)址接口地址:
1.接口地址: http://www.wx-url.cn/sina.php?url_long=http://www.baidu.com
2.接口地址: /tupian/20230522/tcnjson /tupian/20230522/xinlang $api_url = ''.urlencode($url); $short_url = file_get_contents($api_url); echo $short_url;
JAVA調(diào)用代碼:
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調(diào)用代碼:
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)
1、使用api接口時(shí),只需將 URL=后的鏈接替換成自己這邊需要縮短的長(zhǎng)鏈接即可。
2、接口支持參數(shù)傳遞,當(dāng)鏈接中出現(xiàn) & 符號(hào)時(shí),請(qǐng)用 %26 代替(或者使用url編碼),否則攜帶的參數(shù)會(huì)丟失。
3、填寫鏈接時(shí),必須使用http(s)://協(xié)議,否則API接口將會(huì)無(wú)法生成短鏈接!
以上是“如何利用調(diào)用新浪短鏈接/騰訊短鏈接API接口”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!
分享文章:如何利用調(diào)用新浪短鏈接/騰訊短鏈接API接口-創(chuàng)新互聯(lián)
鏈接地址:http://jinyejixie.com/article38/dshepp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、Google、移動(dòng)網(wǎng)站建設(shè)、搜索引擎優(yōu)化、網(wǎng)站導(dǎo)航、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容