Sample code for 30+ languages & platforms
Classic ASP Requires Chilkat v11.5.0+

curl POST with JSON Input and JSON Output

See more CURL Examples

Demonstrates running a simple curl command with JSON input and JSON output.

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

'  Run the following curl command

'   curl -X POST https://httpbin.org/post \
'        -H "Content-Type: application/json" \
'        -d '{
'              "title": "foo",
'              "body": "bar",
'              "userId": 1
'            }'

'  The backslashes at the end of lines are not required.  Chilkat ignores them if present.
set sbTargetCurl = Server.CreateObject("Chilkat.StringBuilder")
success = sbTargetCurl.AppendLn(" curl -X POST https://httpbin.org/post \")
success = sbTargetCurl.AppendLn("      -H ""Content-Type: application/json"" \")
success = sbTargetCurl.AppendLn("      -d '{")
success = sbTargetCurl.AppendLn("            ""title"": ""foo"",")
success = sbTargetCurl.AppendLn("            ""body"": ""bar"",")
success = sbTargetCurl.AppendLn("            ""userId"": 1")
success = sbTargetCurl.AppendLn("          }'")

set httpCurl = Server.CreateObject("Chilkat.HttpCurl")

'  Run the curl command.
success = httpCurl.DoYourThing(sbTargetCurl.GetAsString())
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( httpCurl.LastErrorText) & "</pre>"
    Response.End
End If

set responseJson = Server.CreateObject("Chilkat.JsonObject")
responseJson.EmitCompact = 0

success = httpCurl.GetResponseJson(responseJson)

statusCode = httpCurl.StatusCode
Response.Write "<pre>" & Server.HTMLEncode( "response status code: " & statusCode) & "</pre>"

Response.Write "<pre>" & Server.HTMLEncode( responseJson.Emit()) & "</pre>"

'  Output:

'  response status code: 200
'  {
'    "args": {},
'    "data": "{\r\n            \"title\": \"foo\",\r\n            \"body\": \"bar\",\r\n            \"userId\": 1\r\n          }",
'    "files": {},
'    "form": {},
'    "headers": {
'      "Content-Length": "96",
'      "Content-Type": "application/json",
'      "Host": "httpbin.org",
'      "X-Amzn-Trace-Id": "Root=1-69e8db8b-459b3bdf7b7a3bc749184968"
'    },
'    "json": {
'      "body": "bar",
'      "title": "foo",
'      "userId": 1
'    },
'    "origin": "123.222.222.222",
'    "url": "https://httpbin.org/post"
'  }

'  ----------------------------------------------------------------------------------
'  Another example:

'  curl -X POST https://postman-echo.com/post \
'       -H "Content-Type: application/json" \
'       -d '{"foo":"bar"}'

targetCurl = "curl -X POST https://postman-echo.com/post -H ""Content-Type: application/json"" -d '{""foo"":""bar""}'"

'  Run the curl command.
success = httpCurl.DoYourThing(targetCurl)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( httpCurl.LastErrorText) & "</pre>"
    Response.End
End If

success = httpCurl.GetResponseJson(responseJson)

statusCode = httpCurl.StatusCode
Response.Write "<pre>" & Server.HTMLEncode( "response status code: " & statusCode) & "</pre>"

Response.Write "<pre>" & Server.HTMLEncode( responseJson.Emit()) & "</pre>"

'  Output:

'  response status code: 200
'  {
'    "args": {},
'    "data": {
'      "foo": "bar"
'    },
'    "files": {},
'    "form": {},
'    "headers": {
'      "host": "postman-echo.com",
'      "content-length": "13",
'      "content-type": "application/json",
'      "x-forwarded-proto": "https",
'      "accept-encoding": "gzip, br"
'    },
'    "json": {
'      "foo": "bar"
'    },
'    "url": "https://postman-echo.com/post"
'  }

%>
</body>
</html>