1

I am running ColdFusion 2016 developer edition. I am using cfhttp to test some settings on a remote Apache web server. Is there a way to set the User Agent? The default seems to be set to ColdFusion. When I use cfhttpparam to try to set a new value:

<cfhttpparam type="header" name="user-agent" value="Test UA">

this new value simply gets added and I get:

"ColdFusion, Test UA"

NOTE: I know that the user-agent header is not a reliable measure to use as it can be changed by the user. However, both my servers are test servers and I'm running tests to help me create some settings on more reliable measures.

PeterKA
  • 24,158
  • 5
  • 26
  • 48
  • 1
    Does using the useragent attribute instead improve the situation? – Kevin B Sep 20 '17 at 21:31
  • That's it! `useragent` attribute of `cfhttp`. Thanks @KevinB! ..... Any clue why someone would downvote the question? – PeterKA Sep 20 '17 at 21:37
  • @KevinB please feel free to post an answer. – PeterKA Sep 20 '17 at 21:40
  • I would, but... i don't exactly know why what you originally tried didn't work. I could assume that it's just appending to the header, but then... why does that not also occur for content-type? idunno. – Kevin B Sep 20 '17 at 21:41
  • There seems to be a distinction between attributes (no wonder in cfscript they have `setAttribute()` method) and parameters ( in cfscript they have `addParam()` method). Not sure if that makes any sense – PeterKA Sep 20 '17 at 21:49
  • Feel free to post an answer if you want, I just don't like posting a "try this" answer that doesn't include a reason. There's nothing in the documentation about this behavior – Kevin B Sep 20 '17 at 21:51
  • Will do. Thanks. – PeterKA Sep 20 '17 at 22:09

1 Answers1

2

As hinted by @KevinB, cfhttp has a useragent attribute which can be used as shown below.

Here is what worked:

<cfhttp url=".." ... useragent="Test UA"> .... </cfhttp>

And the remote server sees:

"Test UA"

In cfscript I'm able to set it this way:

httpService = new http(url="...", ...., useragent="Test UA"); //OR

httpService.setAttributes( useragent="Test UA" ); //Once httpService has been instantiated

CFHTTP Attributes

useragent String Default: ColdFusion

Text to put in the user agent request header. Used to identify the request client software. Can make the CFML application appear to be a browser.

https://cfdocs.org/cfhttp

PeterKA
  • 24,158
  • 5
  • 26
  • 48