Baidu Short URL 서비스 소개 : http://www.baidu.com/search/dwz.html
일반적으로 PHP에서 구현되므로 구현에 ASP를 사용하는 방법은 실제로 아래에 작성된 임시 데모를 참조하십시오 (다음 코드를 ASP 파일로 저장하십시오).
--------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------- ------------------------------------------------- ---------------
<%@language = vbscript CodePage = 65001%>
<%
응답. charset = utf-8
세션 .codepage = 65001
세션. 타임 아웃 = 1440
Server.ScriptTimeout = 99999
'원격 획득
기능 posthttppage (posturl, postset, postdata, postreferr)
악기 (lcase (posturl), http : //) = 0 인 경우
posthttppage = $ null $ : 종료 함수
끝 If
다음에 오류가 재개됩니다
희미한 posthtp
'set posthttp = server.createobject (msxml2.xmlhttp)
'set posthttp = server.createobject (microsoft.xmlhttp)
posthttp = server.createobject (msxml2.serverxmlhttp)
'set posthttp = server.createobject (msxml2.serverxmlhttp.3.0)
'set posthttp = server.createobject (msxml2.serverxmlhttp.4.0)
posthttp. 세트 타임 아웃 10000, 10000, 15000, 15000
posthttp.open post, posturl, false
posthttp.setrequstheader content-length, len (postdata)
posthttp.setRequestheader content-type, application/x-www-form-urlencoded
posthttp.setRequestHeader 참조, postreferr
posthttp.send postdata
posthttp.reamstate <> 4 및 posthttp.status <> 200 인 경우
posthttp = 아무것도 설정하지 않습니다
posthttppage = $ null $ : 종료 함수
끝 If
posthttppage = bytestobstr (posthttp.responsebody, postset)
posthttp = 아무것도 설정하지 않습니다
err.number <> 0 인 경우 err.clear
postppage = 또는 isnull (posthttppage) 인 경우 posthttppage = $ null $
엔드 기능
기능 bytestobstr (body, cset)
희미한 objstream
set objstream = server.createobject (adodb.stream)
objstream.type = 1
objstream.mode = 3
objstream.open
objstream.write?
objstream.position = 0
objstream.type = 2
objstream.charset = cset
bytestobstr = objstream.readtext
objstream.close
objstream = 아무것도 설정하지 않습니다
엔드 기능
기능 urlencoding (Datastr)
Dim Strreturn, SI, Thiskr, InnerCode, Hight8, Low8
strreturn =
si = 1 to len (datasts)의 경우
theychr = mid (datasts, si, 1)
IF ABS (ASC (thiscr)) <& hff는 그때
strreturn = strreturn & thiskr
또 다른
InnerCode = ASC (thischr)
내부 코드 <0이면
InnerCode = InnerCode + & H10000
끝 If
Hight8 = (내부 코드 및 & HFF00)/ & HFF
LOW8 = 내부 코드 및 & HFF
strreturn = strreturn & % & hex (hight8) & % & hex (low8)
끝 If
다음
urlencoding = strreturn
엔드 기능
dim test_url : test_url = url = http://www.vevb.com/develop/asp/v74697
dim p_data : p_data = urlencoding (test_url)
Dim V_DATE : V_DATE = POSTHTPPPAGE (http://www.dwz.cn/create.php, utf-8, p_data, http://www.dwz.cn)
응답으로 얻은 JSON 데이터 : & v_date & <br/>
dim v_json : set v_json = toobject (v_date)
응답. 원본 웹 사이트 : & v_json.longurl & <br/>
응답. 짧은 URL : & v_json.tinyurl & <br/>
v_json = 아무것도 설정하지 않습니다
%>
<script language = jscript runat = server>
기능 toobject (json) {
평가 (var o = + json);
반품 o;
}
</스크립트>
--------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------- --------------------------------------------------------- --------
위의 코드 결과는 다음과 같습니다.
JSON 데이터 : {longurl : http://www.vevb.com//develop//asp/v74697,status : 0, tinyurl : http : ///www.dwz.cn/2gggul}
원본 웹 사이트 : http://www.vevb.com/develop/asp/v74697
획득 한 짧은 URL : http://www.dwz.cn/2ggul
위는 단순히 운영 원리를 작성하는 것입니다.