The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> ColdFusion Development
|
How to output from cfhttp
Discuss How to output from cfhttp in the ColdFusion Development forum on Dev Shed. How to output from cfhttp ColdFusion Development forum discussing CFML coding practices, tips on CFML, and other CFML related topics. Find out why ColdFusion is the tool of choice for many e-commerce developers.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 10th, 2012, 03:15 AM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 14
Time spent in forums: 2 h 32 m
Reputation Power: 0
|
|
|
How to output from cfhttp
Hi,
I have a page where it tries to get the value from another server using the cfhttp. Then using the cfhttpparam its iterates through all the form fields and then construct a structure. This structure is then appended to an array using arrayAppend.
My query is I want to see if all the form fields and values that has been inserted into the structure. I tried to put cfoutput, but its not working inside cfhttp.
Could any one please help me out in this?
Many thanks in advance
This is the code snippet
<cfhttp url="#URL#" throwonerror="yes" method="post" timeout="300">
<cfloop list="#listSort(structKeyList(form),'textnocase')#" index="i">
<cfif i is not "fieldnames">
<cfset arrayOfValues = listToArray(evaluate('form.#i#'),',') />
<cfif arrayLen(arrayOfValues) LT 2>
<cfhttpparam type="formfield" name="#i#" value="#evaluate('form.#i#')#" />
<cfset tempStruct = structNew() />
<cfset tempStruct.name = i />
<cfset tempStruct.value = evaluate('form.#i#') />
<cfset tempStruct.from = 'form' />
<cfset arrayAppend(array1,tempStruct) />
<cfelse>
<cfloop from="1" to="#arrayLen(arrayOfValues)#" index="j">
<cfhttpparam type="formfield" name="#i#" value="#arrayOfValues[j]#" />
<cfset tempStruct = structNew() />
<cfset tempStruct.name = i />
<cfset tempStruct.value = arrayOfValues[j] />
<cfset tempStruct.from = 'form' />
<cfset arrayAppend(array1,tempStruct) />
</cfloop>
</cfif>
</cfif>
</cfloop>
</cfhttp>
|

February 10th, 2012, 09:25 AM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
Try CFDUMP .
Or, just build up the structure before you make the CFHTTP call.
|

February 13th, 2012, 01:20 AM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 14
Time spent in forums: 2 h 32 m
Reputation Power: 0
|
|
|
Hi Kiteless...it worked and i was able to get the array values. But now I am stuck up in another issue. This array1 is being passed to another cfm file and there we have a div id where we are trying to display the content from the cfhttp using cfhttp.FileContent. But its not giving any result.
<div id="result" style="display: none;">
<cfif IsDefined("cfhttp.FileContent")>
<cfoutput>inside result</cfoutput>
<cfoutput>#updateURL(cfhttp.FileContent)#</cfoutput>
</cfif>
</div>
It is printing inside result. But the remaining is blank. When I googled i could see, if the response is saved as file, cfhttp.FileContent is blank. I tried <cfoutput>Error detail: #cfhttp.errorDetail#</cfoutput> to check if it displays ant error. But no error is displayed.
Is there any way out there for displaying the contents?
Any advise would be helpful....
Thank you...
|

February 13th, 2012, 08:42 AM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
What happens if you go to the page you're trying to load with CFHTTP directly in your browser? Does it work?
|

February 13th, 2012, 09:10 PM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 14
Time spent in forums: 2 h 32 m
Reputation Power: 0
|
|
|
yea it works....
|

February 13th, 2012, 10:18 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
So you're saying if you go to the URL in your browser, it works, but if you invoke the URL with CFHTTP and then dump the CFHTTP call, there is no value in any of the properties of the object and no error? As far as I know, that's impossible.
To add, it seems to mean that either you're using CFHTTP incorrectly or something else is going on (like the site being inaccessible to the CF server, etc.). But even then CFHTTP would return a 404 error or some other HTTP status code. It won't just return nothing.
Last edited by kiteless : February 13th, 2012 at 10:22 PM.
|

February 13th, 2012, 10:51 PM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 14
Time spent in forums: 2 h 32 m
Reputation Power: 0
|
|
|
I can give you more details on this.
There is a page called as a header page and has a form which submits the request to the SAS server and gets the result and displays in a new window.
<form id="form1" action="<cfoutput>#application.settings.SASURL#</cfoutput>" method="POST" target="_blank" onSubmit="return submitForm(this)">
SO it directly displays the result
Now I wanted to add some more features like adding a button. On clicking on this button it should do a couple of more processes including displaying the result from sas.
So I have changed the form action to
<form id="form1" action="index.cfm" method="POST" target="_blank" onSubmit="return submitForm(this)">
This index.cfm includes so many other files and does the processing. Say it includes file1.cfm, file2,cfm
In one of the file (lets say file1.cfm), it uses cfhttp to connect to the SASURL and gets the values
<cfhttp url="#application.settings.SASBrokerURL#" throwonerror="yes" method="post" timeout="300">
Then using the cfhttpparam its iterates through all the form fields from the header page and then gets the value to an array. This is what file1.cfm does.
Then next include in the index.cfm is file2.cfm
Here it builds up the page for displaying the result from sas.
<div id="SASData" style="display: none;">
<cfif IsDefined("cfhttp.FileContent")>
<cfoutput>#alterLinks(cfhttp.FileContent)#</cfoutput>
</cfif>
</div>
<cffunction name="alterLinks" returntype="string" access="private" output="false">
<cfargument name="SASString" required="true" type="string" />
<cfset var returnString = SASString />
<!--- re-aim sorting links to proxy page --->
<!--- single quote version --->
<cfset returnString = REReplaceNoCase(returnString,'<a href=('')[^('')]+broker\?','<a href=''index.cfm?action=SAS_proxy&Report_Type=#Report_Type#&','all')>
<!--- double quote version --->
<cfset returnString = REReplaceNoCase(returnString,"<a href=("")[^("")]+broker\?","<a href=""index.cfm?fuseaction=SAS_proxy&Report_Type=#Report_Type#&",'all')>
<!--- check for ending style tag --->
<cfset htmlStart = findNoCase('<html>',returnString) />
<cfset htmlStart2 = findNoCase('<html>',returnString,htmlStart+1) />
<cfset styleStart = findNoCase('<style',returnString) />
<cfset styleEnd = findNoCase('</style>',returnString) />
<!--- if SAS passes an HTML start tag--->
<cfif htmlStart GT 0>
<!--- if there is a style tag before the html tag --->
<cfif styleStart GT 0 AND (styleStart LT htmlStart OR styleStart LT htmlStart2)>
<!--- if there is not an end style tag before the html tag --->
<cfif styleEnd is 0 OR htmlStart LT styleEnd>
<cfreturn replaceNoCase(returnString,'<html>','</style><html>','all') />
</cfif>
</cfif>
</cfif>
<cfreturn returnString />
</cffunction>
Now when it comes here, no result is being displayed.
When I tried cfdump cfhttp.filecontent, its giving the following output
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"> <html> <head> <meta name="Generator" content="SAS Software Version 9.3, see www.sas.com"> <meta http-equiv="Content-Type" content="text/html"> <title>SAS Output Frame</title> </head> <frameset frameborder="yes" cols="23%,*"> <frame marginwidth="4" marginheight="0" src="some name value pairs with session id" name="contents" scrolling="auto" title="The Table of Contents"> <frame marginwidth="9" marginheight="0" src="some name value pairs with session id" name="body" scrolling="auto" title="The SAS Output"> <noframes> <body> <ul> <li><a href="some name value pairs with session id">The Table of Contents</a></li> <li><a href="some name value pairs with session id">The Contents</a></li> </ul> </body> </noframes> </frameset> </html> </U><DIV STYLE="text-align:left"><HR> <ADDRESS> This request took 0.54 seconds of real time (v9.3 build 1496). </ADDRESS></DIV>
So if we combine the SASURL and the above src, "some name value pairs with session id", it is displaying the output
I checked for error, but its not displaying error also.
So is there anything related to session. whether the session is not maintained when we change the action to index.cfm?
Hope you understood my problem. Really I am stuck.Please advice me
Many Thanks in advance...
|

February 13th, 2012, 11:31 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
So if I follow correctly: - You've got a form on your page that the user can press to make a request to the SAS server, and this works.
- You're trying to mimic this call with CFHTTP
If that's the case it's almost certainly a security problem. CFHTTP makes the ColdFusion server send an HTTP request to the target URL. So unless the account that the ColdFusion service is running under has permissions to call the URL this isn't going to work. Which either means adding that account to the permissions on the target server, or having the CFHTTP call pass whatever cookies or authentication tokens that the user's browser would send.
To add, if the SAS server is maintaining a session for the user, that would also be a problem because the request that the CF server sends would not be using whatever token/cookie identifies the user's session. The SAS server would treat it as a brand-new, standalone request.
Last edited by kiteless : February 13th, 2012 at 11:37 PM.
|

February 14th, 2012, 12:03 AM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 14
Time spent in forums: 2 h 32 m
Reputation Power: 0
|
|
|
There are 2 scenarios in the current functionality
1. For the first scenario, I have got a form and the user press submits and it calls the SAS server using CFHTTP and the result is displayed.
<form id="headerForm" action="index.cfm" method="POST" target="chartmain">
2. For the second scenario, currently its a stand alone call to the SAS server without the cfhttp.
<form id="form1" action="<cfoutput>#application.settings.SASURL#</cfoutput>" method="POST" target="_blank" onSubmit="return submitForm(this)">
Now, I want to make the second standalone scenario similar to the first. ie, by calling the SAS server using cfhttp and getting the result form SAS. Its not working..
|

February 14th, 2012, 02:09 AM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
In that case I'm not sure what to tell you because I'm not totally clear on what you're saying. Your previous post seems to indicate that if you cfdump the second cfhttp.filecontent (for your second cfhttp call), you're getting a result. Is the content you showed the correct result you're expecting from the SAS server?
If the answer is yes (the filecontent is correct), then I'm still not clear on what you're actually asking (since that would mean that it is working). If the answer is no (the filecontent in your dump is not what you're expecting), then the only thing I can think of is that you're making the call with an incorrect URL or incorrect cfhttpparam values.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|