• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2960
  • Last Modified:

cfhttp

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
MMsabry
Asked:
MMsabry
2 Solutions
 
pinaldaveCommented:
value="#form.cart_order_id# "
there is a space at the end of this variable before " does that matter...
0
 
MMsabryAuthor Commented:
thanks, but nop nothing happens, no redirection!
0
 
Tacobell777Commented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
jyokumCommented:
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
 
jyokumCommented:
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
 
MMsabryAuthor Commented:
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
 
jyokumCommented:
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
 
MMsabryAuthor Commented:
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
 
TimDgCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now