-1

I have a script ready in Postman, but I can't export it to VBSCRIPT because in postman it has Body with JSON and Params (path Variables) with KEY and VALUE. How to include both information in XMLHTTP POST? O God!

EndPointLink = "http://localhost:8080/sessions/addcard"
set http=CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.open "POST",EndPointLink

'Body
strDataRaw =  "{""id"":""55119"",""type"":""number"",""message"":{""text"":""Hello""}}"

http.setRequestHeader "Content-Type","application/json"
http.setRequestHeader "sessionId=Super"

http.send strDataRaw

This script works very well. But now, I need to pass two parameters, which already worked in Postman, but I don't know how to add them to this script.


'Params Path Variables Postman Key and Value:

Key="sessionId"
Value="2021"
Description="Session ID"

Or Only: "SessionId" = "2021"

How to add the parameters together with the Body or separately? I don't know. Can someone write this solution?

Asp Classic and Vbscript

Thanks and Best Regards.

The script without the "SessionID" from error.

{
    "error": "Session not found"
}
KenMX
  • 1
  • 1

1 Answers1

0

As far as I know there is no native JSON support in vbscript, you can just concatenate your variables into a json string.

Key="sessionId"
Value="2021"
Description="Session ID"

strDataRaw =  "{""key"":""" & Key & """,""value"":""" & Value & """,""description"":""" & Description & """,""id"":""55119"",""type"":""number"",""message"":{""text"":""Hello""}}"
Musa
  • 96,336
  • 17
  • 118
  • 137