Coldfusion cfhttp - have a URL var that is breaking the get function

282 Views Asked by At

I am trying to perform a cfhttp post and I need to include a URL in the URL vars to give directions to where to deposit a delivery receipt.

Here is my code:

    <cfhttp result="CFHTTP" method="GET" url="http://xxxxxxxxxxx/send-sms.php?sender=#numbers.number#&to=#get_sms.receiver#&message=#get_sms.msgdata#&dlr-url=#get_sms.dlr_url#">
    <cfhttpparam type="formfield" name="sender" value="#numbers.number#">
    <cfhttpparam type="formfield" name="to" value="#get_sms.receiver#">
    <cfhttpparam type="formfield" name="message" value="#get_sms.msgdata#">
    <cfhttpparam type="formfield" name="dlr-url" value="#get_sms.dlr_url#">
</cfhttp> 

And everything works if I do not include the dlr_url which is similar to the following:

http://entry.xxxxxxxx.com/process_dlr.cfm?status=%d&msisdn=%p&dlr-mask=31&data=%a&batchid=161F3CE3-E031-9CFF-7364A9C1AC50AA5B&destination=2&accountID=123&sub_id=123456789&carrierID=2222

I can only assume that items like "?" and "&" would be breaking the process. Any ideas on how to accomplish this?

Thank you all for any help.

2

There are 2 best solutions below

2
Scott On

I don't what I was thinking....

Needed to encode: #URLEncodedFormat(get_sms.dlr_url)#

Sorry I didn't think of thanks!!!

0
Alex On

There are some flaws here.

  1. Don't specify query params manually in the url attribute. Use <cfhttpparam param type="url" instead.
  2. A GET request does not support a body (form data), so <cfhttpparam type="formfield" is not going to do anything.
  3. Why are you even trying to send the same params via query string AND body?

If you use the proper cfhttpparam tags, you don't have to encode the values manually.

Proper request with params via query string

<cfhttp result="CFHTTP" method="GET" url="http://xxxxxxxxxxx/send-sms.php">
    <cfhttpparam type="url" name="sender"  value="#numbers.number#">
    <cfhttpparam type="url" name="to"      value="#get_sms.receiver#">
    <cfhttpparam type="url" name="message" value="#get_sms.msgdata#">
    <cfhttpparam type="url" name="dlr-url" value="#get_sms.dlr_url#">
</cfhttp> 

Proper request with params via query string AND body

<cfhttp result="CFHTTP" method="POST" url="http://xxxxxxxxxxx/send-sms.php">
    <cfhttpparam type="url"       name="sender"  value="#numbers.number#">
    <cfhttpparam type="url"       name="to"      value="#get_sms.receiver#">
    <cfhttpparam type="url"       name="message" value="#get_sms.msgdata#">
    <cfhttpparam type="url"       name="dlr-url" value="#get_sms.dlr_url#">
    <cfhttpparam type="formfield" name="sender"  value="#numbers.number#">
    <cfhttpparam type="formfield" name="to"      value="#get_sms.receiver#">
    <cfhttpparam type="formfield" name="message" value="#get_sms.msgdata#">
    <cfhttpparam type="formfield" name="dlr-url" value="#get_sms.dlr_url#">
</cfhttp>

The difference: POST allows query string and body payload. GET only allows query string.

I assume you are more familiar with PHP, so here's how the type attribute translates:

  • type="url" name="sender" => $_GET['sender']
  • type="formfield" name="sender" => $_POST['sender']