I am trying to send to the server a JSON string. If I use CFHTTP, cfhttp.filecontent becomes a Byte Array whereas when I use PostMan it returns a string as we expect.
What am I doing wrong?
var row = { a = 1, b = 2};
cfhttp(
url="http://127.0.0.1:8199/api/?event=user.create"
method="post"
result="result"
){
cfhttpparam(type="body" encoded="false" value="#serializeJSON(row)#")
}
dump by cfhttp:
dump by postman
Don’t forget to tell us about your stack!
OS: Windows 10 Java Version: 11.0.11 Lucee Version: 5.3.7.48
The api call returns a new user after inserting it in the database.
The problem mainly relies on the request body (before we even receive a response) which is encoded when sent by the cfhttp function.
To sum up, whereas when we call the api through postman the request body undergoes no change, when using cfhttp the fileContent gets converted into a byte array. We have found no solution in the documentation.
I encountered a similar issue in the past and now always add getasbinary=“no” to my CFHTTP requests. (NOTE: I’ve had to use “no” instead of boolean or else ACF will throw an error.)