Skip to main content
Silverwulf
Known Participant
Nov 8, 2016 6:26 PM UTC
Question

cfhttp GET request removes certain Headers?

Question:

Does a cfhttp request, using a GET method, remove Headers such as Content-Type?

And if so, is there a way around this?

Problem:

I'm making an external API call that requires certain information be passed within the Content-Type header ...

<cfhttpparam type="header" name="Content-Type" value="application/json">

vs.

<cfhttpparam type="header" name="Content-Type" value="application/xml">

to determine the type of information returned to me. JSON or XML.

When attempting to use the first param type, it returns an Error. However, when doing so with a POST method, it does not.

The second param type works no matter what type of method I use.

I'm using ColdFusion 11.

I would really prefer to be working with JSON, but if I can't get JSON data back when I'm not using POST, I'll have to resort to using XML, a far less appealing option.

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Legend
Nov 10, 2016 1:54 AM UTC

I could be wrong but the Content-Type header refers to the data payload you are sending, not the expected response. With a GET request, there is no payload - everything is contained in the header.

Translate
Silverwulf
Known Participant
Nov 10, 2016 7:05 PM UTC

Steve Sommers wrote:

I could be wrong but the Content-Type header refers to the data payload you are sending, not the expected response. With a GET request, there is no payload - everything is contained in the header.

Yes, I believe that's correct.

I'm not an expert in this area by any means. So I can't really say for certain, but from what I've been able to understand, that is the way it works. The "Content-Type" header wouldn't really be necessary in your typical GET request.

However, since I AM getting back a response and that response can be given back to me in either XML or JSON format, I have to specify my preference to the application, that I'm making my API call to, in some fashion.

Unfortunately, this application seems to have chosen to use the "Content-Type" header as a type of variable to tell them which kind of response I want in return (XML or JSON). This doesn't seem to be a problem for them in languages like .net and php because those languages don't appear to strip that header out of the call for a GET method.

However, it appears that ColdFusion does. And I need to verify that in order to know whether I'm going to be able to get around this issue or not.

Translate
EddieLotter
Inspiring
Nov 8, 2016 7:13 PM UTC

If you use your browser to request the JSON page, do you see the JSON data in your browser?

I'm wondering if you are getting a misleading error. The code that generates the JSON page might be at fault.

Cheers

Eddie

Translate
Silverwulf
Known Participant
Nov 9, 2016 9:11 PM UTC

EddieLotter wrote:

If you use your browser to request the JSON page, do you see the JSON data in your browser?

I'm wondering if you are getting a misleading error. The code that generates the JSON page might be at fault.

Cheers

Eddie

The application that I'm attempting to interface with actually has a small app that allows you to test API calls against it. So using that small app, I can see JSON calls being sent to and from the server. So I know JSON can come from the program. And using a POST method, I can even get back JSON from my own program without using theirs. It only seems to be an issue with GET calls.

Translate