我有这个输入参数(复杂的输入列表),需要作为HTTP POST请求的一部分发送。我一直在寻找相当于封装以下数据的AutoIt,但不成功。
由于显而易见的输入不完整原因(无法发送 ip_list 和其他数组类型参数),下面给出的工作代码失败了400 - Bad Request
。
$oHttp.Send()
的下列给定数据?如何封装数据类型,如:
null - aligned_device_template 参数
白色间隔值 - description 和
空数组 - 主机名或 device_groups
{
"name": "SnmpSIM",
"description": "EM7 device created by BDD test case",
"credentials":"{{feature.credential.body.result_set[*].URI}}",
"organization": "/api/organization/0",
"aligned_device_template": null,
"aligned_collector": "{{feature.appliance_id[0].id[0]}}{{feature.appliance_id[0].id[1]}}",
"discover_non_snmp": "1",
"scan_ports": [
"21",
"22",
"23",
"25",
"80"
],
"ip_lists": [
{
"start_ip": "{{feature.json.ip}}",
"end_ip": "{{feature.json.ip}}"
}
],
"dhcp_enabled": "0",
"duplicate_protection": "1",
"model_device": "1",
"log_all": "1",
"scan_all_ips": null,
"port_scan_timeout": null,
"initial_scan_level": null,
"scan_throttle": null,
"interface_inventory_timeout": "600000",
"max_interface_inventory_count": "10000",
"bypass_interface_inventory": "0",
"hostnames": [],
"device_groups": []
}
; The data to be sent
$sPD = 'name=SnmpSIM&description=EM7 device created by BDD test case&credentials=37&organization=/api/organization/0&aligned_device_template=null&aligned_collector=1&discover_non_snmp=1&dhcp_enabled=0&duplicate_protection=1&model_device=1&log_all=1&scan_all_ips= null&port_scan_timeout= null&initial_scan_level= null&scan_throttle= null&interface_inventory_timeout=600000&max_interface_inventory_count=10000&bypass_interface_inventory=0&hostnames=&device_groups=&scan_ports=21'
; Creating the object
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "http://10.2.4.18/api/discovery_session", False)
$oHTTP.SetCredentials("username","password",0)
$oHTTP.SetRequestHeader("Content-Type", "application/em7-resource-uri")
; Performing the Request
$oHTTP.Send($sPD)
; Download the body response if any, and get the server status response code.
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status
If $oStatusCode <> 200 then
MsgBox(4096, "Response code", $oStatusCode)
EndIf
; Saves the body response regardless of the Response code
$file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists
FileWrite($file, $oReceived)
FileClose($file)
Dim Items As New Collection
Dim Item As Dictionary
Dim Id As Long
For Id = 1 To 2
Set Item = New Dictionary
Item("iditem") = Id
Item("amount") = 1
Items.Add Item
Next Id
Request.AddBodyParameter "id", 5633
Request.AddBodyParameter "items", Items
$oDictionary = ObjCreate("Scripting.Dictionary")
$oDictionary.ADD("start_ip", "10.20.7.31")
$oDictionary.ADD("end_ip", "10.20.7.33")