小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

MSXML2.ServerXMLHTTP使用實(shí)例

 趨明 2012-02-17

 

(2006-04-15 09:48:30)

MSXML2.ServerXMLHTTP使用實(shí)例

  • 作者:----
  • 來(lái)源:網(wǎng)絡(luò)
  • 編輯:backer
  • 時(shí)間:2006-04-05
  • 類別:asp
  • 第 1 頁(yè) 一個(gè)實(shí)例

 

<%
'使用范例
'讀取URL 的HTML
dim myHttp
set myHttp=new xhttp
myHttp.URL="Response.Write(myHttp.html)

'保存遠(yuǎn)程圖片到本地
myHttp.URL="
'為防止xhttp卡死的情況,使用超時(shí),錯(cuò)誤處理
dim sHtmlcode,iStep
myHttp.URL="
http://www."
sHtmlcode=myHttp.html
iStep=0
do while myHttp.xhttpError=""
 Response.Write("ERROR: AGAIN!<br />")
 sHtmlcode=myHttp.html
 iStep=iStep+1
 if iStep=1 then
  Response.Write("ERROR:OVER!<hr />")
  exit do
 end if
loop
Response.Write(sHtmlcode)

set myHttp=nothing


'--------------------------------------------------------------------
Class xhttp
 private cset,sUrl,sError
 Private Sub Class_Initialize()
  'cset="UTF-8"
  cset="GB2312"
  sError=""
 end sub
 
 Private Sub Class_Terminate()
 End Sub
 
 Public Property LET URL(theurl)
  sUrl=theurl
 end property
 public property GET BasePath()
  BasePath=mid(sUrl,1,InStrRev(sUrl,"/")-1)
 end property
 public property GET FileName()
  FileName=mid(sUrl,InStrRev(sUrl,"/")+1)
 end property
 public property GET Html()
  Html=BytesToBstr(getBody(sUrl))
 end property
 
 public property GET xhttpError()
  xhttpError=sError
 end property
 
 private Function BytesToBstr(body)
  on error resume next
  'Cset:GB2312 UTF-8
  dim objstream
  set objstream = Server.CreateObject("adodb.stream")
  with objstream
  .Type = 1 '
  .Mode = 3 '
  .Open    
  .Write body  '
  .Position = 0 '
  .Type = 2  '
  .Charset = Cset  '
  BytesToBstr = .ReadText '
  .Close
  end with
  set objstream = nothing
 End Function
 
 private function getBody(surl)
  on error resume next
  dim xmlHttp
  'Set xmlHttp=server.createobject("Msxml2.XMLHTTP.4.0")
  'set xmlHttp=server.createobject("Microsoft.XMLHTTP")
  set xmlHttp=server.createobject("MSXML2.ServerXMLHTTP")
  xmlHttp.setTimeouts 10000,10000,10000,30000
  xmlHttp.open "GET",surl,false
  xmlHttp.send
  if xmlHttp.readystate=4 then
  'if xmlHttp.status=200 then
   getBody=xmlhttp.responsebody
  'end if
   else
   getBody=""
  end if
  
  if Err.Number<>0 then
  sError=Err.Number
  Err.clear
  else
  sError=""
  end if
  set xmlHttp=nothing
 end function
 
 Public function saveimage(tofile)
  on error resume next
  dim objStream,imgs
  imgs=getBody(sUrl)
  Set objStream = Server.CreateObject("ADODB.Stream")
  with objStream
  .Type =1
  .Open
  .write imgs
  .SaveToFile server.mappath(tofile),2
  .Close()
  end with
  set objstream=nothing
 end function
end class
%>

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多