Last active
February 25, 2016 09:53
-
-
Save scott-ad-riley/345df4430b0120cb86c2 to your computer and use it in GitHub Desktop.
Bug with CF serializeJSON and CF implicit type conversion that breaks things.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- content with header application/json comes through as binary ---> | |
<cfoutput> | |
#toString(getHttpRequestData().content)# | |
</cfoutput> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
endpointURL = "http://localhost:3000/endpoint.cfm"; //change this to your localhost/environment | |
public function bugRequest () { | |
var httpService = new http(); | |
httpService.setMethod("post"); | |
// post to the url of your endpoint.cfm | |
httpService.setURL(endpointURL); | |
var body = StructNew(); | |
body["cid"] = "245672e4"; // note that this is stored as a string | |
scheduleBodyJSON = serializeJSON(body); | |
// removing the security prefix CF adds when it serializes JSON | |
scheduleBodyJSON = Replace(scheduleBodyJSON, "//", ""); | |
httpService.addParam(type="header", name="Content-Type", value="application/json"); | |
httpService.addParam(type="body", value=scheduleBodyJSON); | |
writeOutput(httpService.send().getPrefix().fileContent); | |
} | |
public function workingRequest () { | |
var httpService = new http(); | |
httpService.setMethod("post"); | |
// post to the url of your endpoint.cfm | |
httpService.setURL(endpointURL); | |
var body = StructNew(); | |
body["cid"] = "72142984eh"; // note that this is stored as a string | |
scheduleBodyJSON = serializeJSON(body); | |
// removing the security prefix CF adds when it serializes JSON | |
scheduleBodyJSON = Replace(scheduleBodyJSON, "//", ""); | |
httpService.addParam(type="header", name="Content-Type", value="application/json"); | |
httpService.addParam(type="body", value=scheduleBodyJSON); | |
writeOutput(httpService.send().getPrefix().fileContent); | |
} | |
bugRequest(); | |
workingRequest(); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment