Skip to main content
Participant
April 28, 2008
Answered

Dynamic Parameters for a CFHTTP POST Request

  • April 28, 2008
  • 2 replies
  • 818 views
I need to call a service using CFHTTP (Post) but the parameters passed to the service are dynamic so there is no way to create a static list of CFHTTPPARAM tags. Actually, there are some static parameters but there will always be dynamic parameters that are included in the request based on the values defined for the static parameters.

My question is how do I pass form data in a CFHTTP POST request when the parameters that are to be passed are not known in advance? I see that there is a type attribute for the CFHTTPPARAM tag of "head" and "body" so I was thinking it might be possible to manually build the data that is passed, but are what is the proper way to pass form parameters if I construct the "head" and "body" data myself?
This topic has been closed for replies.
Correct answer Newsgroup_User

What is wrong with dynamic <cfhttpparam...> tags. That is why they exist.

<cfset foo = structNew()>
<cfset foo.joe = "aValue">
<cfset foo.bob = "bValue">

<cfhttp ...>
<cfloop collection="#foo#" item="bar">
<cfhttpparam name="#bar#" value="#foo[bar]#">
</cfloop>
</cfhttp>

2 replies

mediablurAuthor
Participant
April 28, 2008
I had no idea that you could create CFHTTPPARAM tags dynamically in a loop. Thank you very much for the example -- it looks like it will be an ideal solution.
Newsgroup_UserCorrect answer
Inspiring
April 28, 2008

What is wrong with dynamic <cfhttpparam...> tags. That is why they exist.

<cfset foo = structNew()>
<cfset foo.joe = "aValue">
<cfset foo.bob = "bValue">

<cfhttp ...>
<cfloop collection="#foo#" item="bar">
<cfhttpparam name="#bar#" value="#foo[bar]#">
</cfloop>
</cfhttp>