Serviço de URL curto do Baidu Introdução: http://www.baidu.com/search/dwz.html
Geralmente, é implementado no PHP, portanto, como usar o ASP para implementação é realmente muito simples.
-------------------------------------------------------- -------------------------------------------------------- -------------------------------------------------------- ------- ------------------------------------------- ------------------
<%@Idioma = vbscript codePage = 65001%>
<%
Response.CharSet = UTF-8
Session.codePage = 65001
Session.Timeout = 1440
Server.scriptTimeout = 99999
'Aquisição remota
Função pósthttppage (posturl, postset, pós -data, pós -holo)
Se Instr (lcase (posturl), http: //) = 0 então
Posthttppage = $ null $: função de saída
Final se
Em erro de erro em seguida
Dim posthtp
'Definir posthttp = server.createObject (msxml2.xmlHttp)
'Definir posthttp = server.createObject (Microsoft.xmlHttp)
Definir posthttp = server.createObject (msxml2.serverxmlHttp)
'Definir posthttp = server.createObject (msxml2.serverxmlhttp.3.0)
'Definir posthttp = server.createObject (msxml2.serverxmlhttp.4.0)
Posthttp.setTimeouts 10000, 10000, 15000, 15000
Posthttp.open post, posturl, falso
Posthttp.setReqUStheader Length, Len (PostData)
Posthttp.setRequestHeader-Type, Application/X-Www-Form-Form-Urlencoded
Posthttp.setRequestHeader Referent, Postreferr
Posthttp.send PostData
Se posthttp.reamstate <> 4 e posthttp.status <> 200 então
Definir posthttp = nada
Posthttppage = $ null $: função de saída
Final se
Posthttppage = bytestobstr (posthttp.Responsebody, pós -venda)
Definir posthttp = nada
Se err.number <> 0 o err.clear
Se pós -PAGE = ou ISNULL (posthttppage) então posthttppage = $ null $
Função final
Função bytestobstr (corpo, cset)
ObjStream dim
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
definir objstream = nada
Função final
Função Urlencoding (Datatr)
Dim Strreturn, Si, Thiskr, InnerCode, Hight8, Low8
Strreturn =
Para Si = 1 a Len (Datassal)
Thischr = MID (DATASTR, SI, 1)
Se abs (asc (thiscr)) <& hff então
Strreturn = strreturn & thiskr
Outro
InnerCode = ASC (Thischr)
Se InnerCode <0 então
InnerCode = InnerCode + & H10000
Final se
Hight8 = (InnerCode e & hff00)/ & hff
Low8 = InnerCode e & hff
Strreturn = strreturn & % & hex (Hight8) & % & Hex (Low8)
Final se
Próximo
Urlencoding = strreturn
Função final
Dim test_url: test_url = url = http://www.vevb.com/devell/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)
Dados JSON obtidos por resposta.write: & v_date & <br/>
Dim v_json: Set V_json = ToObject (v_date)
Site original de resposta.Write: & v_json.longul & <br/>
Response.Write URL curto: & v_json.tinyurl & <br/>
Definir v_json = nada
%>
<idioma de script = jscript runat = servidor>
Função toObject (json) {
Eval (var o = + json);
Retornar o;
}
</script>
-------------------------------------------------------- -------------------------------------------------------- -------------------------------------------------------- -------------------------------------------------------- -------------------------------------------------------- --------------------------------------------------—- -------------------------------------------------------- --------
Os resultados do código acima são os seguintes:
Dados JSON obtidos: {Longurl: http:///www.vevb.com//devell//asp/v74697,status: 0, Tinyurl: http: ///www.dwz.cn/2ggul}
Site original: http://www.vevb.com/devell/asp/v74697
O URL curto obtido: http://www.dwz.cn/2ggul
O acima é simplesmente escrever o princípio operacional.