使用https发布数据不会在服务器端进行处理

时间:2013-04-02 10:21:56

标签: vbscript

我有一个从第三方应用程序调用的VBScript,该脚本从第三方应用程序获取数据,并通过以POST格式传递数据在IE浏览器中打开URL。当我使用http作为协议时脚本工作正常但是当我使用https时,服务器端代码(request.getParameter(“param1”))抱怨它无法在请求对象中找到参数。通过传递URL和数据来调用脚本。例如run.vbs https://xyz.com?param1=1234。以下是vbscript供你细读。当我使用https作为协议时,你能告诉我我失踪了吗?任何帮助都非常感谢。非常感谢。

If WScript.Arguments.Count = 1 Then
uri = WScript.Arguments.Item(0)
'WScript.Echo "Arguments " & uri
Set WshNetwork = WScript.CreateObject("WScript.Network")
'WScript.Echo "Current User Name: " & WshNetwork.UserName
filename="C:\Documents and Settings\"+WshNetwork.UserName+"\Application Data\XYZ\Profiles\default\Settings.xml"
'WScript.Echo "Current User fileName: " & filename

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load(filename)
strQuery = "Agent"
Set colItem = xmlDoc.getElementsByTagname(strQuery)
For Each objItem in colItem
    Agentid = objItem.getAttribute("Login")
    'MsgBox "AgentId = " + AgentID
Next

'uri = uri+"^&agentid="+Agentid
uri = uri+"&agentid="+Agentid
pos = InStr(uri,"?")
extracteduri = Mid(uri,1,pos-1)
params = Mid(uri, pos+1)
postdata = Str2Bytes(params,"us-ascii")
header = "Content-Type: application/x-www-form-urlencoded"

Set IE = CreateObject("InternetExplorer.Application")
'IE.Navigate "about:blank"
'IE.AddressBar = True
'IE.ToolBar = True
'IE.StatusBar = True
IE.Visible = True
'WScript.Sleep 2000
Set shl = WScript.CreateObject("WScript.Shell")
shl.SendKeys "% X" 
IE.Navigate extracteduri, Nothing, Nothing, postdata, header
Wscript.Quit
 Else
Wscript.Echo "Usage: RunURL.vbs <URL to invoke>"
Wscript.Quit
 End If
 Function Str2Bytes(Text, CharSet)
Const adTypeText = 2
Const adTypeBinary = 1

  'Create Stream object
  Dim BinaryStream 'As New Stream
  Set BinaryStream = CreateObject("ADODB.Stream")

  'Specify stream type - we want To save text/string data.
  BinaryStream.Type = adTypeText

  'Specify charset For the source text (unicode) data.
  If Len(CharSet) > 0 Then
    BinaryStream.CharSet = CharSet
  Else
    BinaryStream.CharSet = "us-ascii"
  End If

  'Open the stream And write text/string data To the object
  BinaryStream.Open
  BinaryStream.WriteText Text

  'Change stream type To binary
  BinaryStream.Position = 0
  BinaryStream.Type = adTypeBinary

  'Ignore first two bytes - sign of
  BinaryStream.Position = 0

  'Open the stream And get binary data from the object
  Str2Bytes = BinaryStream.Read
End Function

我现在使用以下函数从服务器获取响应,使用h​​ttps作为协议,POST作为格式,但服务器仍然无法看到参数

Set req = CreateObject("MSXML2.ServerXMLHTTP")
'Set the below option to get rid of the "Certificate authority is invalid or     
     'incorrect, error code - 80072F0D" error
req.setOption 2, 13056
req.open "POST", extracteduri, False
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
encodedParams = Escape(params)
WScript.Echo "encodedParams: " & encodedParams
req.send encodedParams
WScript.Echo "req.responseText: " & req.responseText

以下是编码参数 UUI%3DU1%3D123456%26agentid%3D123456

服务器仍然抱怨请求对象中缺少参数。

我正在使用相同的脚本(XMLHTTP请求),但我使用Str2Bytes函数加密参数(在上面声明)

Set req = CreateObject("MSXML2.ServerXMLHTTP")
req.setOption 2, 13056
req.open "POST", extracteduri, False
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.send postdata
WScript.Echo "req.responseText: " & req.responseText

1 个答案:

答案 0 :(得分:0)

我建议使用XMLHTTPRequest而不是Internet Explorer COM对象。有关示例,请参阅here。请注意,发布数据中必须包含encode个特殊字符。

但是,如果你想在IE中打开URL,你可能最好坚持使用原始方法。在那种情况下,我会检查服务器以获取有关服务器端认为无法找到参数的原因的更多信息。请求是否还有一个名为"param1"的参数?