4 Replies Latest reply on Nov 10, 2016 11:05 AM by Silverwulf

    cfhttp GET request removes certain Headers?

    Silverwulf Level 1

      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.

        • 1. Re: cfhttp GET request removes certain Headers?
          EddieLotter Level 3

          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

          • 2. Re: cfhttp GET request removes certain Headers?
            Silverwulf Level 1

            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.

            • 3. Re: cfhttp GET request removes certain Headers?
              Steve Sommers Level 4

              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.

              • 4. Re: cfhttp GET request removes certain Headers?
                Silverwulf Level 1

                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.