在 MS Access 上处理 VBA 中的特殊字符
Handle Special Characters in VBA on ms Access
我正在编写 VBA 代码来检查对我的数据库的访问:
代码检查我是否有权连接到 Web 服务器,以便它授予我访问数据库的权限。
Function WebVer(ByVal StrUserName As String, ByVal StrPassword As String) As String
Dim Access As String
Dim objHTTP As Object
Dim URL As String
Dim Response As String
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "http://myweb.com/authenticator?app=WebDNC_server&service=authenticate&userid=" & StrUserName & "&password=" & StrPassword
objHTTP.Open "GET", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.Send ("")
LDAPResponse = UCase(objHTTP.responseText)
If Response Like "*BAD*" Then
WebVer= "BAD PASSWORD"
ElseIf Response Like "*PASS*" Then
WebVer= "PASS"
ElseIf Response Like "*USERID*" Then
WebVer= "USERID Not RECOGNIZED"
Else
WebVer= "CONNECTION ERROR"
End If
End Function
现在一切正常,除了如果用户在密码中使用特殊字符,它 returns BAD Password。我认为 VBA 如何处理特殊字符存在问题,但仍然不知道如何解决。任何帮助将不胜感激。
我很确定您必须 URL 对用户名和密码进行编码。
参见:How can I URL encode a string in Excel VBA?
我正在编写 VBA 代码来检查对我的数据库的访问: 代码检查我是否有权连接到 Web 服务器,以便它授予我访问数据库的权限。
Function WebVer(ByVal StrUserName As String, ByVal StrPassword As String) As String
Dim Access As String
Dim objHTTP As Object
Dim URL As String
Dim Response As String
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "http://myweb.com/authenticator?app=WebDNC_server&service=authenticate&userid=" & StrUserName & "&password=" & StrPassword
objHTTP.Open "GET", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.Send ("")
LDAPResponse = UCase(objHTTP.responseText)
If Response Like "*BAD*" Then
WebVer= "BAD PASSWORD"
ElseIf Response Like "*PASS*" Then
WebVer= "PASS"
ElseIf Response Like "*USERID*" Then
WebVer= "USERID Not RECOGNIZED"
Else
WebVer= "CONNECTION ERROR"
End If
End Function
现在一切正常,除了如果用户在密码中使用特殊字符,它 returns BAD Password。我认为 VBA 如何处理特殊字符存在问题,但仍然不知道如何解决。任何帮助将不胜感激。
我很确定您必须 URL 对用户名和密码进行编码。
参见:How can I URL encode a string in Excel VBA?