How to CFDUMP the "Body" of an HTTP POST
Asked Answered
G

2

6

Here's my question of the day. Let's say I have this on one page:

start.cfm

<cfset body = { "stuff": [ 1,2,3,4,5 ] }>

<cfhttp url="end.cfm" method="post" result="httpResp" timeout="60">
    <cfhttpparam type="header" name="Content-Type" value="application/json">
    <cfhttpparam type="body" value="#serializeJSON(body)#">
</cfhttp>

I can't figure out what end.cfm needs to have to output what's in the body. I've tried to cfdump everything from variables to form to cgi but I can't get to it. What am I missing?

Gestation answered 29/11, 2018 at 14:25 Comment(0)
G
10

Such a dumb question that I was able to answer it with some additional Googling.

 <cfdump var="#GetHttpRequestData()#">
Gestation answered 29/11, 2018 at 14:55 Comment(3)
It is a good question. I was unfamiliar with this function. I now see how it can be usefulHermilahermina
Agreed. If you are used dealing with forms and fields, you never think about how to retrieve a body onlyAnalisaanalise
You guys are too kind. I hate it when the answer is literally two Google clicks away!Gestation
C
1

An alternative to the "start and end page to see what's in the request" solution is to use Hyper:

https://www.forgebox.io/view/hyper

It wraps cfhttp but does so in a manner that lets you re-use elements of your request that are shared with other calls to the same endpoints. It's especially useful when paired with Wirebox and Coldbox but these are not necessary.

Cornered answered 30/11, 2018 at 13:40 Comment(1)
Thanks for this...first time seeing Forgebox. CommandBox really has breathed new life into CFML, hasn't it? Great to see my favorite language receiving a second wind. :-)Gestation

© 2022 - 2024 — McMap. All rights reserved.