我正在使用vbscript来测试REST Web服务,该服务接受json作为请求,并以json格式响应。我收到HTTP 500 - 内部服务器错误作为响应。这是代码:
Set objStream = CreateObject("ADODB.Stream")
objStream.CharSet = "utf-8"
objStream.Open
objStream.LoadFromFile("C:\request.txt")
restRequest = objStream.ReadText()
objStream.Close
Set objStream = Nothing
contentType ="application/json"
Set oWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
oWinHttp.Open "POST", "http://czcholsint1048.prg-dc.dhl.com:8180/efoms/fulfillOrder", False
oWinHttp.setRequestHeader "Content-Type", contentType
oWinHttp.Send restRequest
response = oWinHttp.StatusText
'response'结果为“内部服务器错误”
我只是想知道在发送请求之前我是否正在转换为字符串json是否会产生任何问题。也许是因为它有 vbcrlf 。
以下是我发送的json请求:
{
"fulfillOrderReq": {
"hdr": {
"messageType": "SALESORDER",
"messageID": "d264502f-aaa2-42a5-a38d-c981ccb99379", "messageVersion": "0.1",
"messageDateTime": "2015-03-20 09:48:29",
"appId": "OMS",
"clientId": "PEP-ESB",
"reqCompId": "77000001"
},
"bd": {
"orders": [
{
"order": {
"orderNumber": "BAYLINETEST512",
"salesChannelOrderNumber": "TMALLTEST512",
"shopName": "拜仁慕尼黑海外旗舰店",
"salesChannel": "天猫订单",
"payType": "支付宝",
"created": "2015-03-20 15:35:58",
"salesChannelMemberName": "mariahliu621",
"salesChannelMemberNo": "M-9837423",
"idCard": "12312",
"idType": "NATIONAL_IDENTIFICATION_NUMBER",
"cnee": {
"name": "SANTOSH",
"address1": "CHINA",
"address3": "CHINA",
"state": "CHINA",
"city": "CHINA",
"country": "CN",
"postCode": "50470",
"telephone": "18610041036",
"mobilePhone": "18610041036"
},
"cneeMemo": "",
"cneeMessage": "",
"sellerMemo": "",
"otherMemo": "",
"actualOrderAmount": "792.0",
"agioAmount": "0.0",
"discountFee": "0.0",
"deliveryCost": "70.0",
"promotionInfo": "",
"orderItems": [
{
"orderItem": {
"productNumber": "184005",
"productName": "蜂拥而至CL克 Flock CL gr.",
"skuNumber": "184005",
"skuName": "Ribéry",
"barcode": "",
"orderGroup": "0",
"productQty": "1",
"amount": "75.0",
"discountFee": "0.0",
"agioPrice": "90.0",
"price": "110.0",
"taxCharges": "100",
"untaxPrice": "50",
"dutyCharges": "9",
"refundStatus": "Normal",
"memo": ""
}
}
]
}
}
]
}
}
}
答案 0 :(得分:1)
你可能已经看过这个,但是因为它们是相关的,所以想在这里分享。 http://forum.universal-devices.com/topic/4335-vbscript-rest-example/
Option Explicit
Dim restReq, url, userName, password
Set restReq = CreateObject("Microsoft.XMLHTTP")
' Replace <node> with the address of your INSTEON device
' Additionally, any REST command will work here
url = "http://isy/rest/nodes/<node>/ST"
' If auth is required, replace the userName and password values
' with the ones you use on your ISY
userName = "admin"
password = "<yourpassword>"
restReq.open "GET", url, false, userName, password
restReq.send
WScript.echo restReq.responseText