很多地方填信息都需要填上域名的備案號,每次使用都得:
搜索備案查詢-點開鏈接-輸入域名-(有些站點還需要輸入驗證碼)-獲取到備案號-複製出來。
這樣的方法太過於繁瑣,我就嘗試搜索了一下域名備案API接口,找到了一些可用的,不過大多都需要註冊登錄或者付費,所以找到一個免費的接口,改改發佈出來。 廢話不多,
接口地址:
http://www.beiancx.cn/icpcx?url_long=http://www.baidu.cn/
接口來源:
調用代碼
HP調用演示:
$url = 'http://www.baidu.com'; $api_url = 'http://www.beiancx.cn/icpcx?url_long=http://www.baidu.cn/; $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.beiancx.cn/icpcx?url_long=http://www.baidu.cn/"); 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.beiancx.cn' path = '/icpcx?url_long' method = 'GET' querys = 'url_long=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)