Skip to main content
Known Participant
October 19, 2012
Question

CFHTTPParam - Multiple named pairs, same field name, passed

  • October 19, 2012
  • 1 reply
  • 648 views

Hi,

I have to hit an API that accepts multiple variables with the post over the URL, but it wants the named pairs.

Here's an example of what they are looking form.

http://www.foo.com/sendEmail.js?CompanyName=ABCCompany&Address=27 Main Street&CompanyName=XYZ Company&Address=35 Main Street... so on and so forth.

However, using cfhttp and looping over cfhttpparam for each record, ColdFusion appears to be creating a comma-delimited list:

http://www.foo.com/sendEmail.js?CompanyName=ABCCompany,XYZ Company&Address=27 Main Street,35 Main Street... so on and so forth.

The API can not handle this method.  Is there a way within the cfhttpparam to force it not create a list?

    This topic has been closed for replies.

    1 reply

    Inspiring
    October 19, 2012

    If there is a loop involved, it was created with source code.  That souce code is probably putting the comma there.

    PS - in coldfusion list functions, the default delimiter is a comma.  That might be relevent.    

    SGrotyAuthor
    Known Participant
    October 19, 2012

    Here's the loop, populating the CFParam Tags.  It's looping over 3 records.

    <cfloop index="i" list="#form.arMH#" delimiters="*">

                        <cfhttpparam name="vMHname"                               type="URL" value="#ListGetAt(i,1,"|")#">

                        <cfhttpparam name="vMHstreet1"                     type="URL" value="#ListGetAt(i,2,"|")#">

                        <cfhttpparam name="vMHcity"                               type="URL" value="#ListGetAt(i,3,"|")#">

                        <cfhttpparam name="vMHstate"                     type="URL" value="#ListGetAt(i,4,"|")#">

                        <cfhttpparam name="vMHzip"                               type="URL" value="#ListGetAt(i,5,"|")#">

                        <cfhttpparam name="vMHcontact"                     type="URL" value="#ListGetAt(i,7,"|")# #ListGetAt(i,8,"|")#">

                        <cfhttpparam name="vMHphone"                     type="URL" value="#ListGetAt(i,6,"|")#">

                        <cfhttpparam name="vMHemail"                     type="URL" value="email@gmail.com">

              </cfloop>

    Here's the dump of the values passed.

    vMHcity

    North Hollywood,Cape Coral,York

    vMHcontact

    Name1,Name2,Name3

    vMHemail

    email@gmail.com,email@gmail.com,email@gmail.com

    vMHname

    Company1,Company2,Company2

    vMHphone

    818-555-1212,239-555-1212,717-555-1212

    vMHstate

    CA,FL,PA

    vMHstreet1

    1 Main St, 34 Main Street, 888 Main Street

    vMHzip

    91605,33904,17404

    I'm not adding the comma's in there.  CF seems to be creating a list of values and pairing it with 1 variable name.

    Oh, and for what it's worth, this has been VERY handy in the past and it's how I expect it to work.  Been this way since 4.5 I believe.  But in this case, I need to force individual pairs because this specific company I'm working with has yet to graduate to webservices.