Solved

cfhttp

Posted on 2004-09-11
9
1,759 Views
Last Modified: 2013-12-24
Can someone give me an example on how to use cfhttp

I'm trying to post some information from my site (hidden form fields) to an online processor,
so i have a page where the hidden form fields are populated with data, then the form submits to a page which contains only a cfhttp tage, but nothing happens.
here is the cfhttp tage that i wrote

<cfhttp  redirect="yes"  url="https://www....." method="post" resolveurl="yes" >
                                          
                                          <cfhttpparam name="sid" type="formfield" value="#form.sid#">
                                          <cfhttpparam name="total" type="formfield" value="#form.Total1#">
                                          <cfhttpparam name="cart_order_id" type="formfield" value="#form.cart_order_id# ">
                                          <cfhttpparam name="demo" type="formfield" value="#form.demo#">
                                    </cfhttp>  
                                    </cfif>
thanks
0
Comment
Question by:MMsabry
9 Comments
 
LVL 21

Expert Comment

by:pinaldave
Comment Utility
value="#form.cart_order_id# "
there is a space at the end of this variable before " does that matter...
0
 

Author Comment

by:MMsabry
Comment Utility
thanks, but nop nothing happens, no redirection!
0
 
LVL 17

Expert Comment

by:Tacobell777
Comment Utility
have you tried creating a normal form and post to this page?
example
<form method="post" action="http://..">
<input ype="text" name="sid" value="test">
etc.....
</form>
0
 
LVL 12

Assisted Solution

by:jyokum
jyokum earned 500 total points
Comment Utility
cfhttp doesn't do redirection. It just sends a request from your cf server to the url in the tag.

To relocate after doing your cfhttp call, you'd have to do something like

<cfhttp ...>
     ...
</cfhttp>

<cflocation url="http://go.somewhere.com">
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 12

Expert Comment

by:jyokum
Comment Utility
if you want to see what was returned from the cfhttp call, put this after it.

<cfdump var="#cfhttp#">

After you make a cfhttp call, you will get back a structure called "cfhttp" that contains all the return information
0
 

Author Comment

by:MMsabry
Comment Utility
Jyokum,
what is the use of the "redirect" attribute of the cfhttp tag then?

Tacobell777'
i have tried that, but nop it does not work.

you see the page i'm posting the info to is the first page of an online processor, and they need the info to be appended to the url, which is easy, my only problem with this, is that the user can see and edit the info on the url and the processor will make him pay the edited amount, which is something i do not want to happen. they indicated to me that their security against that is to send back a hashed key with some information that would allow me to verify that the user has payed the correct amount. but i want to try to avoid this from the start, since if this happens (user editing the total amount) and pays, it will be up to me to chase him to get the correct amount from the start.

now i have once managed to get the cfhttp tag to work (which i do not remember how) and passed all the information correctly without the  rest of the url showing the info. as url param. but at that one time, only the first page on the processor got the information (this page asks the user how does he want to pag) then it moves to the second page where the payment itself occurs. this second page did not get the information and thus displayed a total of "0".

so one thing i was trying to do, is to pass the information using the cfhttp tag, and append the variables to it as hidden form fields. this is where i'm stuck at the moment.

any solutions or work arounds??
thanks
sabry
0
 
LVL 12

Accepted Solution

by:
jyokum earned 500 total points
Comment Utility
according to the documentation (http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-p58.htm) the redirect attribute:
-------------------------------------
If the response header includes a Location field, determines whether to redirect execution to the URL specified in the field.

Yes redirects execution to the specified page.
No stops execution and returns the response information in the cfhttp variable, or throws an error if the throwOnError attribute is True.

The cfhttp.responseHeader.Location variable contains the redirection path. ColdFusion follows a maximum of four redirects on a request. If there are more, ColdFusion functions as if redirect ="no".
-------------------------------------

The important thing to remember about cfhttp is that the SERVER (not the client) is making a request to the url specified. The redirect attribute just controls how the server handles the request.

What payment service is this? A little more info may help  us get you a solution.
0
 

Author Comment

by:MMsabry
Comment Utility
the payment service is 2checkout.com
I have got the the payment processor to work, but only if the user presses a submit button (hidden form fields are submitted then), i would still like to get it to just redirect. so the user does not have to press submit three times through the process
first submit, then verify and submit then pay. I would like to take that last step out, and just diplay a page for about 10s. then it goes to the processor.

I would like also to know how to use the cfhttp tag, and why it is not redirecting in my case!
thanks
0
 
LVL 1

Expert Comment

by:TimDg
Comment Utility
You mention that the service you are submitting to requires the information appended to the URL.  The way you are executing your cfhttp it is submitting form POST data.  What you want to do is submit form GET data.  Adjusting your code it would look like the following:

<cfhttp  url="https://www....." method="get" resolveurl="yes">
     <cfhttpparam name="sid" type="URL" value="#form.sid#">
     <cfhttpparam name="total" type="URL" value="#form.Total1#">
     <cfhttpparam name="cart_order_id" type="URL" value="#form.cart_order_id# ">
     <cfhttpparam name="demo" type="URL" value="#form.demo#">
</cfhttp>

You will receive the http response back from the server in the #cfhttp.FileContent# variable.  After your cfhttp block you will need to parse this variable to get your payment status code.

The redirect parameter in cfhttp is defaulted to YES.  This parameter allows the cfhttp request to accept and execute redirects from the url requested up to 4 times.  It DOES NOT perform any kind of redirection for the page user.

After you parse your status code then you will want to do one of two things:
Execute a <cflocation url="statuspageX.cfm"> tag that redirects the user to a special status explanation page -or-
if you want to show them their status and redirect them after 10 seconds or so then you will have to use a javascript timer.

0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now