Hi all. I need to do the following
1. Log into a website
2. click a link
3 download a file by clicking a button (and accepting the file download in the pop up)
Can I do this in coldfusion?
Grizzly9279 - 18 Sep 2007 22:33 GMT
In theory yes, but it's not easy.
Speaking at a high level, you'll need to do the following:
1) CFHTTP POST your login credentials.
2) Analyze response for successful/unsuccessful login
3) If unsuccessful login, abort with error message
4) If successful login, capture cookie/state variables returned
5) If you know what the address of the file to download is going to be ahead
of time, use CFHTTP GET (passing along all cookie/state vars explicitely) to
retrieve the file and save it to disk on the CF-server
**If the address of the file to download is dynamic, you can try using CFHTTP
GET to retrieve the raw HTML of the page that displays the "link" in question,
and you can then use regular expression searches to locate and discover the
address of the file you want to download.
I hope this helps.
SilentBob'secretfusion - 19 Sep 2007 14:03 GMT
Hmmm. This forum is acting funky this morning. Messages appearing and
disappearing.
Anyway, to be honest. I am alittle lazy and don't really want to code all
this. Do applications exist which can capture the users actions, record them,
then repeat them when required.
aredovian - 19 Sep 2007 14:51 GMT
C++ or Visual Basic would be much better langauges for this type of
application. I'm sure there are applications doing this already but you might
need to do some deep searching, however, instructions on how to do this are
really easy to find. Here is one link that explains how to do it...
http://http://dn.codegear.com/article/30197
Grizzly9279 - 19 Sep 2007 23:40 GMT
[q][i]Originally posted by: [b][b]SilentBob'secretfusion[/b][/b][/i]
Hmmm. This forum is acting funky this morning. Messages appearing and
disappearing.
Anyway, to be honest. I am alittle lazy and don't really want to code all
this. Do applications exist which can capture the users actions, record them,
then repeat them when required.
[/q]
JMeter (http://jakarta.apache.org/jmeter/ ) can actually do exactly what
you're asking for. With Jmeter, you can "record" a user's session clicking
around a web site, and you can save it to a "test plan". You can then re-run
that "test plan" over and over again. You can also configure it to run
multiple "threads" (users) performing those actions at the same time.
This tool often comes in handy for performance and load testing, but can be
used for a variety of other purposes.
Ian Skinner - 18 Sep 2007 22:45 GMT
Are you talking about building a website where users can login and
download files you are hosting with the site?
This is trivial and the only part that would require actual CFML code is
the login verification. Everything else could technically be straight HTML.
Or are you asking how to use ColdFusion to login to another site and
download files from the remote site to the CF server.
That is the process Grizzly described.
SilentBob'secretfusion - 19 Sep 2007 13:50 GMT
No... What I mean is can I create an application in coldfusion that doest the
following:
1. Logs into a website (for example www.needreport.com)
2. Provides login credentials upon request of www.needreport.com
3. After login happens, the coldfusion application will click a link imbedded
in www.needreport.com.
Basically, I need to create an application which acts like a user using a
browser.
Can this be done in coldfusion, if not, does any know of an application or a
language which do this?
BKBK - 19 Sep 2007 19:40 GMT
[i]1. Logs into a website (for example www.needreport.com)
2. Provides login credentials upon request of www.needreport.com[/i]
<cfhttp url="http://www.needreport.com/login.cfm" method="post">
<cfhttpparam name="username" type="FormField" value="me_myself">
<cfhttpparam name="password" type="FormField" value="1243">
</cfhttp>
[i]3. download a file[/i]
<cfhttp method="Get" url="http://www.needreport.com/downloadPage.cfm"
throwOnError="Yes" />
We assume the download file is embedded in downloadpage.cfm by means of the
combination cfheader/cfcontent. In this way the host server could arrange a
login and download session for you.
BKBK - 19 Sep 2007 20:26 GMT
Hmmm... I spoke too quick. When I got down to testing it I found that i could
only download text files in this manner. Binaries give encoding problems. Will
look into it some other time. Not feeling too well.
BKBK - 23 Sep 2007 06:48 GMT
Back to my last post as promised. My first experiment with downloading binaries
using cfhttp in that way led to an encoding problem.
However, I have solve it. I simply applied the functions and .
<!---
downloadPage.cfm (on first Coldfusion server, e.g. needReport.com)
=====================================================================
--->
<cfcontent type="application/msword"
file="c:\coldfusion8\wwwroot\forDownload\report.doc">
<!---
getReport.cfm (on a second Coldfusion server)
=================================================
--->
<cfhttp getasbinary="yes" url="http://www.needreport.com/downloadPage.cfm"
throwOnError="Yes" />
<cffile action="WRITE" file="c:\coldfusion8\wwwroot\report\sept07report.doc"
output="#toBinary(toBase64(cfhttp.filecontent))#">