Skip to main content
Participating Frequently
May 15, 2025
Question

Fixed Accept header property in http reqeust, can't change it

  • May 15, 2025
  • 2 replies
  • 1077 views

Hello,

I am using cf 23 and facing the issue when trying to communicate with remote api on spring. 


This is my cf codebase:

var httpService = new http(url=url, method="DELETE", timeout=5);
httpService.addParam(type="header", name="Accept",  value="application/json");
httpService.addParam(type="header", name="cfId", value="123");
httpService.addParam(type="header", name="cfToken", value="555-555");
var httpServiceResponse = httpService.send();

I am trying to delete import/test.xml file on sftp server and if I invoke the call from postman or anywhere else it will work but when I invoke this from CF in request headers it's always fixed accept=application/xml, text/xml;
here are headers from spring service
 - REQUEST headers: [cfid=123; accept=application/xml, text/xml; charset=UTF-8; cftoken=555-555; user-agent=ColdFusion; content-length=0; host=localhost:8806; connection=Keep-Alive; accept-encoding=gzip,deflate]

What ever I do I can't change Accept Header param value!
It says here in Providing accept header that any call with .xml, the accept parameter would be set to application\xml
https://helpx.adobe.com/coldfusion/developing-applications/changes-in-coldfusion/restful-web-services-in-coldfusion.html

I honestly do not want to change spring service because of this.
Please let me know if there is a way to change this and how can I enforce correct Accept value or remove the header property complely?!

Thanks in advance

    2 replies

    Charlie Arehart
    Community Expert
    Community Expert
    May 15, 2025

    Flipout, I really think you have something else going on there in your environment--perhaps a proxy or firewall or a/v tool that is making that manipulation. Here's how you can prove it.

     

    Change the URL in your code to call this domain instead: 

     
    As you may know, httpbin.org is a nifty service that allows you to make calls and see what IT received. The front page explains how it works.  When I run it with your code, it shows just the accept you expect.
     
    Finally, BKBK, while it's true that folks should stop using the http cfc (and CF2025 removes it), ntoe that you don't need to switch to tags. There is the long-existing (since cf11) cfhttp statement. His code could be written as:
    <cfscript>
    cfhttp( url="https://httpbin.org/delete", timeout=5, result="httpServiceResponse", method="delete" ) {
    	cfhttpparam( name="Accept", type="header", value="application/json" );
    	cfhttpparam( name="cfId", type="header", value=session.CFID );
    	cfhttpparam( name="cfToken", type="header", value=session.CFTOKEN );
    }
    writeDump( var=httpServiceResponse );
    </cfscript>

     

    As always, just trying to help. I hope you both will let me know what you think of the above.

    /Charlie (troubleshooter, carehart. org)
    flipoutAuthor
    Participating Frequently
    May 16, 2025

    Hi Charlie,
    There is nothing in between these two machines that is making any kind of manipulation and I can prove this by using my chunk of code and just removing .xml from url

    <cfhttp
                    url="http://localhost:8806/sftp/private/remove/import/test"
                    method="delete"
                    timeout="5"
                    result="httpServiceResponse">
       
                    <cfhttpparam type="header" name="Accept" value="application/json">
                    <cfhttpparam type="header" name="cfId" value="#session.CFID#">
                    <cfhttpparam type="header" name="cfToken" value="#session.CFTOKEN#">
    </cfhttp>

    This will be passed to spring:

    2025-05-16 07:17:18,398 [pas-sftp] DEBUG c.a.p.c.c.f.RequestLoggingFilter [471dcac405ab;;;] - REQUEST headers: [cfid=123; accept=application/json; cftoken=555-555; user-agent=ColdFusion; content-length=0; host=localhost:8806; connection=Keep-Alive; accept-encoding=gzip,deflate]


    If I remove  <cfhttpparam type="header" name="Accept" value="application/json">, like this:

    <cfhttp
                    url="http://localhost:8806/sftp/private/remove/import/test"
                    method="delete"
                    timeout="5"
                    result="httpServiceResponse">
       
                    <cfhttpparam type="header" name="cfId" value="#session.CFID#">
                    <cfhttpparam type="header" name="cfToken" value="#session.CFTOKEN#">
    </cfhttp>

    This is what I get (NO ACCEPT PROPERTY):

    2025-05-16 07:19:14,961 [pas-sftp] DEBUG c.a.p.c.c.f.RequestLoggingFilter [2bc599e487b1;;;] - REQUEST headers: [cfid=123; cftoken=555-555; user-agent=ColdFusion; content-length=0; host=localhost:8806; connection=Keep-Alive; accept-encoding=gzip,deflate]


    If you again just return .xml at the end of xml like the first example I posted without accept as cfhttpparam 

    <cfhttp
                    url="http://localhost:8806/sftp/private/remove/import/test.xml"
                    method="delete"
                    timeout="5"
                    result="httpServiceResponse">
       
                    <cfhttpparam type="header" name="cfId" value="#session.CFID#">
                    <cfhttpparam type="header" name="cfToken" value="#session.CFTOKEN#">
    </cfhttp>


    It will be added with fixed value again (accept=application/xml, text/xml; charset=UTF-8;😞

    2025-05-16 07:21:30,629 [pas-sftp] DEBUG c.a.p.c.c.f.RequestLoggingFilter [79c0be7d1193;;;] - REQUEST headers: [cfid=7548; cftoken=443e2e6bc2450ac9-6B676FA6-A19C-0455-21EE963AAAF094EF; user-agent=ColdFusion; accept=application/xml, text/xml; charset=UTF-8; content-length=0; host=localhost:8806; connection=Keep-Alive; accept-encoding=gzip,deflate]

     Unfortunately on httpbin there is no url with file extension .xml or .json defined at the end, we would have the same problem there.
    So to sum it all up, if url string is ending with .xml or .json extension accept header property will be added to headers with fixed value.
    I tested with bunch of other url strings that are paths to file with extensions like pdf, csv, txt, ai, tiff etc. and all of them work without issues.
    If you guys can configure some remote endpoint to accept filepath as parametar like localhost/service/remove/{pathToFileWithFile} you would get the same issue when the call is invoked from coldfusion and invoking localhost/service/remove/someFolder/test.xml or localhost/service/remove/someFolder/test.json
    Headers will work if you remove file extension 
    Thanks

    Community Expert
    May 16, 2025

    Yeah, you're going to need to contact cfsup at adobe.com and file a bug in tracker.adobe.com.

     

    Dave Watts, Eidolon LLC
    BKBK
    Community Expert
    Community Expert
    May 15, 2025

    I would suggest that you stop using the script-based CFC, new http(). Script-based CFCs, such as http(), were deprecated since ColdFusion 2018, unsupported since ColdFusion 2021 and completedly removed in ColdFusion 2025

    You should use instead the tag or cfscript version of CFHTTP. For example,

    <cfhttp 
        url="http://localhost:8806/sftp/private/remove/import/test.xml" 
        method="delete" 
        timeout="5"
        result="httpServiceResponse">
        
        <cfhttpparam type="header" name="Accept" value="application/json">
        <cfhttpparam type="header" name="cfId" value="123">
        <cfhttpparam type="header" name="cfToken" value="555-555">
    
    </cfhttp>

    Another reference: 

    flipoutAuthor
    Participating Frequently
    May 15, 2025

    Hi,

    Thanks for response, but using script language is not the issue. 
    I did configured the same way you suggested:

    <cfhttp
                    method="delete"
                    timeout="5"
                    result="httpServiceResponse">
       
                    <cfhttpparam type="header" name="Accept" value="application/json">
                    <cfhttpparam type="header" name="cfId" value="#session.CFID#">
                    <cfhttpparam type="header" name="cfToken" value="#session.CFTOKEN#">
    </cfhttp>

    I get this on backend
    2025-05-15 18:27:40,081 [pas-sftp] DEBUG c.a.p.c.c.f.RequestLoggingFilter [2b049cca15a7;;;] - REQUEST headers: [cfid=7254; accept=application/xml, text/xml; charset=UTF-8; cftoken=81ed7be3e4701804-4FBA98CF-FB24-1A00-6AC399B24A037C35; user-agent=ColdFusion; content-length=0; host=172.23.200.150:8080; connection=Keep-Alive; accept-encoding=gzip,deflate]

    If i remove .xml from url like url="http://localhost:8806/sftp/private/remove/import/test"
    I get 
    2025-05-15 18:28:26,219 [pas-sftp] DEBUG c.a.p.c.c.f.RequestLoggingFilter [1cc594821162;;;] - REQUEST headers: [cfid=7255; accept=application/json; cftoken=88252445ef2587ec-4FC1A2C8-CF95-6EB0-A51EFDECCEAA7388; user-agent=ColdFusion; content-length=0; host=172.23.200.150:8080; connection=Keep-Alive; accept-encoding=gzip,deflate]
    so the <cfhttpparam type="header" name="Accept" value="application/json"> is respected.

    Any time u use .xml or .json on url end you will get accept  accept=application/xml, text/xml or accept=application/json in headers no matter if you using script or markup language

    Thanks

    BKBK
    Community Expert
    Community Expert
    May 15, 2025

    Sorry, I think I misunderstood your question. Do I understand correctly that you wish to delete a file from an FTP server? If so, why not use CFFTP instead of CFHTTP?

     

    I still don't understand your question about the application/xml and application/json headers.  Does one work (with cfhttp) and the other does not? If so, which one works and which one doesn't?

     

    In any case, if you place the following line at the end of the cfhttp code, what do you get?

    <cfdump var="#httpServiceResponse#" >