2015-05-07 28 views
0

我正在使用vbscript來測試REST web服務,它接受json作爲請求並以json格式響應。我收到HTTP 500 - 內部服務器錯誤作爲響應。下面的代碼:從vbscript擊打REST web服務

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 

「響應」原來是「內部服務器錯誤」

我只是想知道我正在轉換爲字符串作爲發送請求之前的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

可能重複[如何使在Excel中使用VBA REST調用?](http://stackoverflow.com/questions/19553476/how-to-make-rest-call-with-vba-in -excel) –

回答

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