VB客户端向ASP web 服务器申请数据出错处理
public Sub getDataFromWWW(ByVal strURL As String, ByVal mode As Boolean, Optional ByVal method As String, Optional ByVal strPostData)On Error GoTo getDataFromWWW_Err
Const DNSResolveTime = 10 'DNS解释时间,超时10秒
Const WinsockConnectTime = 10 'Winsock连接时间,超时10秒
Const SentTime = 10 '发送时间,超时10秒
Const ReceiveTime = 30 ',接收时间,超时30秒
Dim xmlObj As String 'xml目标
Dim xmlHttp '
Dim result As String '返回结果
102 xmlObj = "MSXML2.ServerXMLHTTP" '取得xml的串
103 ShowMessageBox "getDataFromWWW", 0, "Perepare Send Request to MyWEB TO USE:" & xmlObj
'Set xmlHttp = Server.CreateObject(xmlObj) '原来的版本
104 Set xmlHttp = CreateObject(xmlObj) '创建http对象
106 xmlHttp.SetTimeOuts DNSResolveTime * 1000, WinsockConnectTime * 1000, SentTime * 1000, ReceiveTime * 1000 'DNS解释时间, Winsock连接时间,发送时间,接收时间。(单位毫秒)
'xmlHttp.Open "POST", strURL, False ' POST 可改为get
108 xmlHttp.Open method, strURL & "?" & strPostData, mode ' 取值
xmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" '"Content-Type: application/x-www-form-urlencoded" & vbCrLf
110 ShowMessageBox "getDataFromWWW", 0, "Send Request to MyWEB Server :" & strURL & "?" & strPostData,
112 xmlHttp.send
114 If xmlHttp.ReadyState = 4 Then '已返回
116 If xmlHttp.Status = 200 Then '成功
'result = xmlHttp.responsebody '取得结果
118 result = xmlHttp.responseText
RaiseEvent DataArrival(reqSrcObj, result)
120 ShowMessageBox "getDataFromWWW", 0, "MyWEB Server Response Succeed: " & result
Else '页面不存在
result = "" '返回为空串
122 RaiseEvent BrowserError(xmlHttp.Status, "MyWEB Server Response Failure,No data Return.")
124 ShowMessageBox "getDataFromWWW", 0, "MyWEB Server Response Failed,resul is NULL. "
End If
Else
result = ""
126 RaiseEvent BrowserError(xmlHttp.ReadyState, "xmlHttp.ReadyState isn't 4 or data does not ready.")
128 ShowMessageBox "getFromURL", 0, "MyWEB Server Response Time OUT,resul is NULL "
Set xmlHttp = Nothing
Exit Sub
getDataFromWWW_Err:
RaiseEvent BrowserError(Err.number, Erl & " line ERROR," & Err.Description)
130 ShowMessageBox "getDataFromWWW", Err.number, Erl & " line ERROR," & Err.Description
End SUB
-------------------------------------------------
问题是:124,128在网络断掉时没有执行。请问如何解决? --------------------编程问答-------------------- 用 Winsock 控件实现? 感觉 Winsock 在编写时容易出问题.. --------------------编程问答-------------------- 不是用winsock的.
102 xmlObj = "MSXML2.ServerXMLHTTP" '取得xml的串
103 ShowMessageBox "getDataFromWWW", 0, "Perepare Send Request to MyWEB TO USE:" & xmlObj
'Set xmlHttp = Server.CreateObject(xmlObj) '原来的版本
104 Set xmlHttp = CreateObject(xmlObj) '创建http对象
直接创建MSXML2 http的对象来取得数据.已经设置了超时的时间,但是如果网断掉了,就一直都不会有回应任何的信息.这很奇怪了. --------------------编程问答-------------------- 为何不用纯API? --------------------编程问答-------------------- 支持!
补充:VB , 网络编程