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

cfhttp GET request removes certain Headers?

Community Beginner ,
Nov 08, 2016 Nov 08, 2016

Copy link to clipboard

Copied

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.

Views

682

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
Advocate ,
Nov 08, 2016 Nov 08, 2016

Copy link to clipboard

Copied

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

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 Beginner ,
Nov 09, 2016 Nov 09, 2016

Copy link to clipboard

Copied

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.

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
Advocate ,
Nov 09, 2016 Nov 09, 2016

Copy link to clipboard

Copied

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.

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 Beginner ,
Nov 10, 2016 Nov 10, 2016

Copy link to clipboard

Copied

LATEST

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.

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