[TR][TD]<script language="vbscript">
|
Sub submit1_onmouseup '当点击“查询”按钮时触发;
|
Dim objXML, objXSL, objFSO,strFile, strFileName, strXSL,strURL,TheForm
|
Set TheForm = Document.wordfind
|
window.status="正在检索数据···"
|
strURL="dns.asp"
|
Set objXML = CreateObject("Microsoft.XMLHTTP") '创建MS的XMLHTTP组件;
|
stra = "submit=submit&fqdn="&TheForm.words.value
|
objXML.Open "post",strURL,false '采用Post提交方式;
|
objXML.setrequestheader "content-length",len(stra)
|
objXML.setrequestheader "content-type","application/x-www-form-urlencoded"
|
objXML.send stra ' 发送信息
|
xmlGet = objXML.responseText '稍等片刻后,得到服务器端传回来的结果;
|
if instr(1,xmlGet,"This is not a valid .com .net .org .info or .biz domain name",1)<1 and len(trim(xmlGet))>100 then
|
if instr(1,xmlGet,"This domain is available",1)<1 then
|
if instr(1,xmlGet,"Registrant:",1) then
|
strFind1 =instr(1,xmlGet,"Registrant:",1)
|
else
|
strFind1 = instr(1,xmlGet,"<pre><FONT face=""Verdana, Arial",1)+65
|
strFind2 = instr(1,xmlGet,"</FONT></pre>",1)
|
strFind4=strFind2-strFind1
|
sHTML = mid(xmlGet,strFind1,strFind4)
|
TheForm.comments.value="查询结果:"+chr(13)+chr(10)+sHTML
|
window.status="查询结果:该域名已被占用"
|
else
|
TheForm.comments.value="恭喜你,此域名可用!"
|
window.status="查询结果:该域名仍然处于可用状态!"
|
end if
|
else
|
TheForm.comments.value= "无效的国际顶级域名!请输入以(.com .net .org .info or .biz)结尾的国际域名, 例如sun.com"
|
window.status="无效的国际顶级域名!请输入以(.com .net .org .info or .biz)结尾的国际域名, 例如CCTV.com"
|
end if
|
Set objXML = Nothing
|
end sub
|
</script>
|
<html><head><title>XMLHTTP之域名查询篇</title></head>
|
<body bgColor=#cccca3>
|
<form method="post" name=wordfind onsubmit="javascript:return false">
|
请输入域名名称:<input type="text" value="cctv.com" name="words" size="69">
|
<input type="submit" value="查询" id=Submit1 name=Submit1>
|
<TEXTAREA name=comments readonly rows=10 cols=76></TEXTAREA>
|
</form></body></html>
|
[/TD][/TR] |
2、服务器端ASP程序:[TR][TD]<%dim xmlGet,objXML, objXSL, objFSO,strFile, strFileName, strXSL,strURL
|
xmlGet=""
|
if len(trim(Request.form("fqdn"))) > 1 then
|
strURL="http://www.domainbank.net/whoisresults_gen.cfm?show=1"
|
'WhoIS服务器的地址
|
Set objXML = CreateObject("Microsoft.XMLHTTP") '创建MS的XMLHTTP组件
|
stra = "submit=submit&fqdn="&trim(Request.form("fqdn"))
|
objXML.Open "post",strURL,false
|
objXML.setrequestheader "content-length",len(stra)
|
objXML.setrequestheader "content-type","application/x-www-form-urlencoded"
|
objXML.send stra ' 发送信息到WhoIs数据库服务器;
|
xmlGet = objXML.responseText ' 取得域名服务器返回的信息
|
Set objXML = Nothing
|
end if
|
response.write xmlGet '返回结果给客户端
|
%>
|
[/TD][/TR] |
在上述过程中,可以发现我们自己的WEB服务器中的ASP程序其实只起到一个中间传递的作用,在实际应用中,也可以省去这个中间层,使用vbscript通过xmlhttp直接向WHOIS数据库发送和接收数据。不过这样的话,可能会因为IE中“通过(其它)域访问数据资源”被禁用(默认)而引起权限不够导致无法执行,所以该省去ASP中间层的方法并不太通用。