ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 10th, 2012, 03:15 AM
Newcf Newcf is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 14 Newcf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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>

Reply With Quote
  #2  
Old February 10th, 2012, 09:25 AM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
Try CFDUMP .

Or, just build up the structure before you make the CFHTTP call.

Reply With Quote
  #3  
Old February 13th, 2012, 01:20 AM
Newcf Newcf is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 14 Newcf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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...

Reply With Quote
  #4  
Old February 13th, 2012, 08:42 AM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
What happens if you go to the page you're trying to load with CFHTTP directly in your browser? Does it work?

Reply With Quote
  #5  
Old February 13th, 2012, 09:10 PM
Newcf Newcf is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 14 Newcf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 32 m
Reputation Power: 0
yea it works....

Reply With Quote
  #6  
Old February 13th, 2012, 10:18 PM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
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.

Reply With Quote
  #7  
Old February 13th, 2012, 10:51 PM
Newcf Newcf is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 14 Newcf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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...

Reply With Quote
  #8  
Old February 13th, 2012, 11:31 PM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
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.

Reply With Quote
  #9  
Old February 14th, 2012, 12:03 AM
Newcf Newcf is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 14 Newcf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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..

Reply With Quote
  #10  
Old February 14th, 2012, 02:09 AM
kiteless kiteless is offline
Moderator
Dev Shed God (5000 - 5499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 5,091 kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level)kiteless User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 53 m 27 sec
Reputation Power: 966
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > How to output from cfhttp

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap