我有一个功能(见下文),它运行良好。我最近将我的代码移到了另一台服务器上,但我没有更改其中的任何内容。它无法在新服务器上运行。
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument: 'Mid'
/calculate.asp, line 416
当我检查第 416 行时,我得到了这个:
Dim result3: result3 = Mid(o3.responseText, Basla3, Bitir3)
这是完整的功能:
<%
Function xyz()
Dim o3: Set o3 = Server.CreateObject("MSXML2.ServerXMLHTTP")
Dim o_date3: o_date3 = split(EndingDate, ".")
Dim s_date3
If (Len(o_date3(2)) = 4) Then
s_date3 = o_date3(2)
Else
s_date3 = "20" & o_date3(2)
End If
If (Len(o_date3(1)) = 2) Then
s_date3 = s_date3 & o_date3(1)
Else
s_date3 = s_date3 & "0" & o_date3(1)
End If
If (Len(o_date3(0)) = 2) Then
s_date3 = s_date3 & o_date3(0)
Else
s_date3 = s_date3 & "0" & o_date3(0)
End If
Dim s3: s3 = "<soapenv:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:AntTransferWSIntf-IAntTransferWS""><soapenv:Header/><soapenv:Body><urn:EURCurrency soapenv:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""><DateStr xsi:type=""xsd:string"">" + s_date3 + "</DateStr></urn:EURCurrency></soapenv:Body></soapenv:Envelope>"
o3.Open "POST", serviceUrl, False
o3.setRequestHeader "Content-Type", "text/xml"
o3.setRequestHeader "Connection", "close"
o3.setRequestHeader "SOAPAction", " "
o3.send s3
Dim hataVarMiBasla3: hataVarMiBasla3 = (InStr(1, o3.responseText, "<faultstring>", vbTextCompare)) + 13
If (hataVarMiBasla3 > 13) Then
Dim hataVarMiBitir3: hataVarMiBitir3 = (InStr(1, o3.responseText, "</faultstring>", vbTextCompare)) - hataVarMiBasla3
Dim hata3: hata3 = Mid(o3.responseText, hataVarMiBasla3, hataVarMiBitir3)
KurGetir = hata3
Else
Dim Basla3: Basla3 = (InStr(1, o3.responseText, """xsd:double"">", vbTextCompare)) + 13
Dim Bitir3: Bitir3 = (InStr(1, o3.responseText, "</return>", vbTextCompare)) - Basla3
Dim result3: result3 = Mid(o3.responseText, Basla3, Bitir3)
xyz = CDbl(Replace(result3, ".", mstrComma))
End If
Set o3 = Nothing
End Function
%>
为什么我会收到这个错误?
最佳答案
Mid(string, start[, length])
不是官方引用,但根据我的经验,如果
- 开始小于或等于零。
- 长度小于零(如果在 Mid 调用中没有错过)
查看错误行和相关的。
Dim Basla3: Basla3 = (InStr(1, o3.responseText, """xsd:double"">", vbTextCompare)) + 13
Dim Bitir3: Bitir3 = (InStr(1, o3.responseText, "</return>", vbTextCompare)) - Basla3
Dim result3: result3 = Mid(o3.responseText, Basla3, Bitir3)
假设 o3.responseText
为空,因为您的代码不检查响应是否为空。
Basla3
根据 InStr() + 13
不能小于 13 ,所以这不是问题。
但是看起来像 Bitir3
根据 InStr() - Basla3
可以小于零(Basla3 评估为 13)。
继续假设,(InStr(1, o3.responseText, "</return>", vbTextCompare))
评估为 0
,然后使用 - Basla3
它将被评估为 -13
.
多田! 规则 2 违反,长度不能小于零。
您的代码的问题是,没有检查响应长度或响应状态。
如果响应为空,请考虑以下事项:
- 您的新服务器可能存在与旧服务器不同的连接问题。
- 您拥有的 API 仅被授权用于旧服务器的 IP 地址。
简而言之,您应该优化代码并确保有xml响应。
至少使用类似的东西:
o3.Send
If o3.readyState = 4 And o3.status = 200 Then
If Len(o3.responseText) > 0 Then
'response is ready to parse
Else
'response status is ok but empty
End If
Else
'request failed
End If
顺便说一句,由于您的请求是一个肥皂电话,我强烈建议您通过使用 DomDocument 等解析 xml 响应来完成这项工作。
替换小数点,使用 Mid & InStr
配对检查节点存在也是麻烦和不好的做法。
关于asp-classic - 无效的过程调用或参数 : 'Mid' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18780142/