'向指定的URL发送字符串。
'参数:iSendURL 目标地址;
' iSendStr 发送的字符串;
' MsgId ,返回网关分配给短信的ID,如果为空串,表示该短信网关没有接收
'返回值:出错信息号。返回 0 为操作成功。
Public Function fPostStr(iSendURL As String, iSendStr As String, msgId As String, Optional resText) As Integer
On Error GoTo lbError
Dim xml_Http As New MSXML.XMLHTTPRequest
Dim xmldoc1 As New MSXML.DOMDocument
Dim xmlelement As MSXML.IXMLDOMElement
Dim iErrNo As Integer
Dim tTimeout As Single
Dim sResType As String
iSendStr = URLEncoding(iSendStr)
Debug.Print iSendStr
tTimeout = Timer
xml_Http.open "POST", iSendURL, True
xml_Http.setRequestHeader "Content-Length", Len(iSendStr)
xml_Http.setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded"
xml_Http.Send iSendStr
Debug.Print iSendStr
While xml_Http.readyState <> 4 And fIsTimeOut(tTimeout) < 0
DoEvents '问题出在该循环上。
Wend
If fIsTimeOut(tTimeout) >= 0 Then
xml_Http.abort
fPostStr = -1
Exit Function
End If
If xml_Http.Status <> 200 Then
fPostStr = xml_Http.Status
Exit Function
Else
xmldoc1.loadXML xml_Http.responseText
'xmldoc1.Load xml_Http.responseStream
If xmldoc1.parseError.errorCode <> 0 Then
fPostStr = -1
Exit Function
Else
sResType = xmldoc1.documentElement.getAttribute("type")
Select Case sResType
Case "sms"
Set xmlelement = xmldoc1.getElementsByTagName("messageid").Item(0)
msgId = Trim(xmlelement.Text)
Case "error"
Set xmlelement = xmldoc1.getElementsByTagName("error").Item(0)
If xmlelement Is Nothing Then
iErrNo = -3
Else
iErrNo = xmlelement.getAttribute("type") * (-1)
End If
fPostStr = iErrNo
Exit Function
Case "sentMessages"
If (Not IsMissing(Result)) Then
resText = xml_Http.responseText
Else
fPostStr = -5
Exit Function
End If
Case Else
fPostStr = -2
Exit Function
End Select
End If
End If
fPostStr = 0
Exit Function
lbError:
fposgstr = -10 '内部错误
End Function-----------
Private Function fIsTimeOut(ByVal iTimeBefore As Single) As Single
Dim tTimeNow As Single
tTimeNow = Timer + 1
If mTIMEOUT < 1 Then mTIMEOUT = 181
fIsTimeOut = Switch(tTimeNow <= iTimeBefore, tTimeNow + 86400, 1, tTimeNow) - iTimeBefore - mTIMEOUT
End Function
-----------------------------------------------
While xml_Http.readyState <> 4 And fIsTimeOut(tTimeout) < 0
DoEvents '问题出在该循环上,循环的次数让程序等待了30多秒。
Wend这个循环为什么大多数情况下会循环那么多次?
'参数:iSendURL 目标地址;
' iSendStr 发送的字符串;
' MsgId ,返回网关分配给短信的ID,如果为空串,表示该短信网关没有接收
'返回值:出错信息号。返回 0 为操作成功。
Public Function fPostStr(iSendURL As String, iSendStr As String, msgId As String, Optional resText) As Integer
On Error GoTo lbError
Dim xml_Http As New MSXML.XMLHTTPRequest
Dim xmldoc1 As New MSXML.DOMDocument
Dim xmlelement As MSXML.IXMLDOMElement
Dim iErrNo As Integer
Dim tTimeout As Single
Dim sResType As String
iSendStr = URLEncoding(iSendStr)
Debug.Print iSendStr
tTimeout = Timer
xml_Http.open "POST", iSendURL, True
xml_Http.setRequestHeader "Content-Length", Len(iSendStr)
xml_Http.setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded"
xml_Http.Send iSendStr
Debug.Print iSendStr
While xml_Http.readyState <> 4 And fIsTimeOut(tTimeout) < 0
DoEvents '问题出在该循环上。
Wend
If fIsTimeOut(tTimeout) >= 0 Then
xml_Http.abort
fPostStr = -1
Exit Function
End If
If xml_Http.Status <> 200 Then
fPostStr = xml_Http.Status
Exit Function
Else
xmldoc1.loadXML xml_Http.responseText
'xmldoc1.Load xml_Http.responseStream
If xmldoc1.parseError.errorCode <> 0 Then
fPostStr = -1
Exit Function
Else
sResType = xmldoc1.documentElement.getAttribute("type")
Select Case sResType
Case "sms"
Set xmlelement = xmldoc1.getElementsByTagName("messageid").Item(0)
msgId = Trim(xmlelement.Text)
Case "error"
Set xmlelement = xmldoc1.getElementsByTagName("error").Item(0)
If xmlelement Is Nothing Then
iErrNo = -3
Else
iErrNo = xmlelement.getAttribute("type") * (-1)
End If
fPostStr = iErrNo
Exit Function
Case "sentMessages"
If (Not IsMissing(Result)) Then
resText = xml_Http.responseText
Else
fPostStr = -5
Exit Function
End If
Case Else
fPostStr = -2
Exit Function
End Select
End If
End If
fPostStr = 0
Exit Function
lbError:
fposgstr = -10 '内部错误
End Function-----------
Private Function fIsTimeOut(ByVal iTimeBefore As Single) As Single
Dim tTimeNow As Single
tTimeNow = Timer + 1
If mTIMEOUT < 1 Then mTIMEOUT = 181
fIsTimeOut = Switch(tTimeNow <= iTimeBefore, tTimeNow + 86400, 1, tTimeNow) - iTimeBefore - mTIMEOUT
End Function
-----------------------------------------------
While xml_Http.readyState <> 4 And fIsTimeOut(tTimeout) < 0
DoEvents '问题出在该循环上,循环的次数让程序等待了30多秒。
Wend这个循环为什么大多数情况下会循环那么多次?
解决方案 »
- 获得字符串在屏幕中的象素宽度
- VB+EXCEL输出的一些细节问题?不够再加,帮顶有分 80分
- 紧急求救:在vb中查询两个相关表中的某个字段。
- 软件(控件)自动下载并安装
- 怎么样用数据控件设置数据源的名称及位置??急!!!!!
- 要不要 使用option explicit,大家写程序有没有使用它 ?
- 如何吧MSHFLEXGRID显示的内容打印出来或者转换为EXCEL格式啊?绝对给分!!!!
- 如何写一个这样的ASP组件???关于图像处理的
- 请问那位大哥知道csdn上上传软件最大能够有多大?有没有限制?40多M的能不能上传上去?
- 内存问题?
- 请问怎样在VB中调用IE浏览器,谢谢!
- 请教VB中的报表问题!
Private Function fIsTimeOut(ByVal iTimeBefore As Single) As Single
Dim tTimeNow As Single
tTimeNow = Timer + 1
If mTIMEOUT < 1 Then mTIMEOUT = 181
fIsTimeOut = Switch(tTimeNow <= iTimeBefore, tTimeNow + 86400, 1, tTimeNow) - iTimeBefore - mTIMEOUT
End Function
这个函数起初运行非常的慢
http://bbs.2ccc.com/uploads/huangtao/smartmail.part2.rar
http://expert.csdn.net/expert/deeptree/rooms/20/list.xml怎 么得到列表啊
兄弟
怎 样提交啊