0

I'm using vbscript to test a REST web service which accepts json as request and responds also in json format. I'm getting HTTP 500 - Internal Server Error as response. Here's the code:

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' turns out as "Internal Server Error"

I just wonder whether the json i'm converting to string before sending as request is creating any problem. Maybe beacuse of vbcrlf's it has.

Below is the json i'm sending as request:

{  
  "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": ""  
            }  
          }  
        ]  
      }  
    }  
  ]  
}  
}  
}  
TylerH
  • 20,799
  • 66
  • 75
  • 101
sidekickbottom
  • 139
  • 1
  • 2
  • 12
  • possible duplicate of [How to make REST call with VBA in Excel?](http://stackoverflow.com/questions/19553476/how-to-make-rest-call-with-vba-in-excel) – Paul Sweatte Jul 01 '15 at 21:18

1 Answers1

2

You may have seen this already however wanted to share this here since they are related. 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
Mendy
  • 147
  • 1
  • 9