Baidu Short URL Service Introduction: http://www.baidu.com/search/dwz.html
Il est généralement implémenté dans PHP, donc comment utiliser ASP pour l'implémentation est en fait très simple.
-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------- ------------------------------------------- ----------------
<% @ Language = codepage VBScript = 65001%>
<%
Réponse.Charset = UTF-8
Session.codepage = 65001
Session.Timeout = 1440
Server.scriptTimeout = 99999
'Acquisition à distance
Fonction posthttppage (postUrl, postset, postdata, postreferr)
Si instr (lcase (postul), http: //) = 0 alors
Posthttppage = $ null $: fonction de sortie
Terminer si
Sur l'erreur reprendre ensuite
Dim Posthtp
'Set posthttp = server.createObject (msxml2.xmlhttp)
'Set posthttp = server.createObject (Microsoft.xmlhttp)
Définir posthttp = server.createObject (msxml2.serverxmlhttp)
'Set posthttp = server.createObject (msxml2.serverxmlhttp.3.0)
'Set posthttp = server.createObject (msxml2.serverxmlhttp.4.0)
Posthttp.settimeouts 10000, 10000, 15000, 15000
Posthttp.open post, posturl, false
Posthttp.setreQUSTHEADER Content-Length, Len (postdata)
Posthttp.setRequestHeader-Type, application / x-www-form-urlencoded
Posthtp.setRequestHeader Référer, PosTreferr
Posthttp.send postdata
Si posthttp.reamstate <> 4 et posthttp.status <> 200 alors
Définir posthttp = rien
Posthttppage = $ null $: fonction de sortie
Terminer si
PosthTTPPAGE = ByTestObstr (posthttp.ResponseBody, postset)
Définir posthttp = rien
Si err.number <> 0 le err.clear
Si postppage = ou isNull (posthttppage) alors posthttppage = $ null $
Fonction finale
Fonction bytestobstr (corps, cset)
Objstream sombre
Définir 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
définir objstream = rien
Fonction finale
Urlencoding de fonction (datastr)
DIM STRRETURN, SI, Thiskr, Innercode, Hight8, Low8
Streturn =
Pour si = 1 à Len (datastr)
ThisChr = mid (datastr, si, 1)
Si ABS (asc (thiscr)) <& hff alors
Streturn = Strreturn & Thiskr
Autre
Innercode = ASC (ThisChr)
Si innercode <0 alors
Innercode = innercode + & h10000
Terminer si
Hight8 = (innercode et & hff00) / & hff
Low8 = Innercode et & HFF
Streturn = Strreturn &% & Hex (Hight8) &% & hex (Low8)
Terminer si
Suivant
Urlencoding = Streturn
Fonction finale
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 = posthtppage (http://www.dwz.cn/create.php, utf-8, p_data, http://www.dwz.cn)
Données JSON obtenues par réponse.write: & v_date & <br/>
Dim v_json: set v_json = toObject (v_date)
Réponse.Write Site Web original: & v_json.longurl & <br/>
Response.write Short URL: & v_json.tinyurl & <br/>
Définir v_json = rien
%>
<Script Language = JScript Runat = Server>
Fonction toObject (json) {
Eval (var o = + json);
Retour o;
}
</cript>
-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------------------------------------------ - - - -------------------------------------------------- --------
Les résultats du code ci-dessus sont les suivants:
Données JSON obtenues: {longurl: http:////www.vevb.com//develop//asp/v74697,status: 0, tinyurl: http: ///www.dwz.cn/2gggul}
Site Web d'origine: http://www.vevb.com/develop/asp/v74697
L'URL courte obtenue: http://www.dwz.cn/2ggul
Ce qui précède consiste simplement à rédiger le principe de fonctionnement.