Skip to main content
Inspiring
July 17, 2019
Answered

Send data with JSON

  • July 17, 2019
  • 1 reply
  • 1061 views

I am trying to learn how to post data to an external site using JSON. The example the vendor gave me looks like this:

curl -XPOST --data '{"audioLevel": 50, "url": "http://some-stream.de/"}'

http://TheirURL.com:7000/device/00:08:e1:06:c5:39/send

From doing some research I think I need to make an array, the SerializeJSON the array then use CFHTTP to send it. I can't find anything that explains the curl -XPOST --data

I am struggling to try to wrap my head around this. Would appreciate any pointers.

Thanks,

Gary

This topic has been closed for replies.
Correct answer Bardnet

You need something like

<cfhttp

method="post"

url="http://TheirURL.com:7000/device/00:08:e1:06:c5:39/send"

throwonerror="Yes">

<cfhttpparam type="body" value="{""audioLevel"": 50, ""url"": ""http://some-stream.de/""}">

</cfhttp>

You can generate the body by building a structure in ColdFusion and use serializeJSON to put it in the value attribute. Take care for the casing of the word audioLevel.

curl is a command line tool that allows to send http requests. It can be used for testing. You can put everything in a cfexecute tag, if you wish. curl is freely available for download on: curl

1 reply

BardnetCorrect answer
Inspiring
July 17, 2019

You need something like

<cfhttp

method="post"

url="http://TheirURL.com:7000/device/00:08:e1:06:c5:39/send"

throwonerror="Yes">

<cfhttpparam type="body" value="{""audioLevel"": 50, ""url"": ""http://some-stream.de/""}">

</cfhttp>

You can generate the body by building a structure in ColdFusion and use serializeJSON to put it in the value attribute. Take care for the casing of the word audioLevel.

curl is a command line tool that allows to send http requests. It can be used for testing. You can put everything in a cfexecute tag, if you wish. curl is freely available for download on: curl

Inspiring
July 18, 2019

The value of an attribute is enclosed in double quotes. When quotes are used in a string they must be doubled.