• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

application/json POST content not returned as binary data

New Here ,
Feb 21, 2021 Feb 21, 2021

Copy link to clipboard

Copied

Hi,

I have a legacy API that uses taffy and CF 2018, and I'm posting json with Content-Type: application/json to the API.

taffy checks for binary data it gets from getHTTPRequestData().content.  The documentation for getHTTPRequestData says that binary data will be returned if the content type doesn't start with 'text' or if it is "application/x-www-form-urlencoded."  

 

I have confirmed that the data are being posted with Content-Type: application/json, but getHTTPRequestData().content is returning a string.  If I cfdump the string, I see the following which appears to contain a representation of the bytes:

 

{"Code":"\u16a0\u16c7\u16bb\u16eb\u16d2\u16e6\u16a6\u16eb\u16a0\u16b1\u16a9\u16a0\u16a2\u16b1\u16eb\u16a0","CodeID":"515","CodeDescription":"foo"}

 

The Code in the JSON was a test string with ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠ.

Would anyone have any ideas how data might be getting garbled before it gets to the taffy CF application.cfc (which extends the taffy.core.api cfc)?  

 

 

<cffunction name="getRequestBody" access="private" output="false" hint="Gets request body data, which CF doesn't do automatically for some verbs">
<!--- Special thanks to Jason Dean (@JasonPDean) and Ray Camden (@ColdFusionJedi) who helped me figure out how to do this --->
<cfset var body = getHTTPRequestData().content />
<!--- on input with content-type "application/json" CF seems to expose it as binary data. Here we convert it back to plain text --->
<cfif isBinary(body)>
<cfset body = charsetEncode(body, "UTF-8") />
</cfif>
<cfreturn body />

Views

158

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

If you use "application/x-www-form-urlencoded", I think the data will likely be passed as string. To ensure binary data will be passed, use "multipart-form-data".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

Thank you for the quick response. The API client is using
'application/json' rather than 'application/x-www-form-urlencoded.' From
what I've read in the docs for getHTTPRequestData, the content should be
returned as binary data for a content type of 'application/json', and taffy
is written in a way that assumes that is the case. I've confirmed that

isBinary(getHTTPRequestData.content)

is false despite the content type being 'application/json'.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

LATEST

You're correct, application/json is text, not binary. I'm not sure why getHttpRequestData would treat it as binary. It used to be, back in the day, that "application/{whatever}" would actually be binary, but JSON is definitely not binary.

 

Dave Watts, Eidolon LLC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation