Solved

cfhttp + redirect not working

Posted on 2004-10-15
10
1,253 Views
Last Modified: 2013-12-24
Hi,

  I am using cfhttp with the "redirect=yes" attribute.  The Responheader DOES return a location AND a 302 statuscode.  However, it is not redirecting.  I am using CFMX 6.0 on Windows.  

  All I am trying to do is submit some info to a site (which is working), and then it normally redirects you to another page using the values from the cookies that were set.  So if there is any way to get the redirect working OR if I can use cfhttp off of the first cfhttp, than that would work as well.

Thanks
Ben
0
Comment
Question by:bptacek
  • 5
  • 5
10 Comments
 

Author Comment

by:bptacek
ID: 12320689
Here is my CFDUMP of CFHTTP:
=============================================
Charset        ISO8859_1
Filecontent       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Header       HTTP/1.1 302 Found Date: Fri, 15 Oct 2004 11:26:42 GMT Server: WebSphere Application Server/4.0 Set-Cookie: JSESSIONID=0000H5MASTBCAC0DIG3SOZ1Z5WA:tuhtsano;Path=/ Cache-Control: no-cache="set-cookie,set-cookie2" Expires: Thu, 01 Dec 1994 16:00:00 GMT Set-Cookie: acct=12313433;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: r1c1=1;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: r1c2=2;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: r1c3=3;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: r1c4=4;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: r1c5=5;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: r1c6=6;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: r2c1=7;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: r2c2=8;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: r2c3=9;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: r2c4=10;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: r2c5=11;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: r2c6=12;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: sortBy=1;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT Set-Cookie: order=a;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT location: https://www.odfl.com/reports/ViewAttachment Keep-Alive: timeout=30, max=100 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: text/html;charset=ISO8859_1 Content-Language: en content-length: 83
Mimetype       text/html
RawHeader       [undefined struct element]
Responseheader       
struct
Cache-Control       no-cache="set-cookie,set-cookie2"
Connection       Keep-Alive
Content-Language       en
Content-Type       text/html;charset=ISO8859_1
Date       Fri, 15 Oct 2004 11:26:42 GMT
Expires       Thu, 01 Dec 1994 16:00:00 GMT
Explanation       Found
Http_Version       HTTP/1.1
Keep-Alive       timeout=30, max=100
Server       WebSphere Application Server/4.0
Set-Cookie       
struct
1       JSESSIONID=0000H5MASTBCAC0DIG3SOZ1Z5WA:tuhtsano;Path=/
10       r2c2=8;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
11       r2c3=9;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
12       r2c4=10;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
13       r2c5=11;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
14       r2c6=12;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
15       sortBy=1;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
16       order=a;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
2       acct=12313433;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
3       r1c1=1;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
4       r1c2=2;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
5       r1c3=3;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
6       r1c4=4;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
7       r1c5=5;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
8       r1c6=6;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
9       r2c1=7;Domain=www.odfl.com;Expires=Sat, 15-Oct-2005 11:26:42 GMT
Status_Code       302
Transfer-Encoding       chunked
content-length       83
location       https://www.odfl.com/reports/ViewAttachment
Statuscode       -1 null
Text       YES
=============================================
0
 

Author Comment

by:bptacek
ID: 12320948
Just tried it on my CFMX 6.1 Linux box and the redirect works, however the page that it redirects to does not show proper page.  I wonder how I keep the same JSESSIONID or does the redirect keep this info when it goes to the next page?
0
 
LVL 5

Expert Comment

by:umbrae
ID: 12321046
coldfusions redirect attribute executes a request to the target of the redirection after the first request and handles the response of the second request like it was the result of the first request.

There are two ways you can possibly use the data you're looking for.

A: The cfhttp.fileContent variable may have the data you're looking for.

B: get rid of the 'redirect' attribute, and do a <cflocation url="#cfhttp.resonseHeader.location#">

Hope this Helps.

-Umbrae
0
Back Up Your Microsoft Windows Server®

Back up 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.

 

Author Comment

by:bptacek
ID: 12321249
Thank for the response umbrae.  I am aware of the cfhttp.responseHeader.location variable.  I am not trying to redirect it on the client side, but on the server side.  The redirected page will give me a TAB-Delimeted file that I need to be able to read and then automatically put the file into a db.  I know how to do the last part, but I need to be able to get to the redirected page to get the tabbed file first.  So I am looking for NO client intervention.

Thanks
Ben
0
 
LVL 5

Expert Comment

by:umbrae
ID: 12321351
I see, I believe I misunderstood your question to begin with. You might be able to execute another cfhttp with some 'cfhttpparam's in order to shove the cookies to the new request.

It might look something like this:

<CFHTTP url="#cfhttp.responseHeader.location#">
<CFHTTPPARAM type="Cookie" name="Cookie1" value="Cookie1Data">
<CFHTTPPARAM type="Cookie" name="Cookie2" value="Cookie2Data">
</CFHTTP>

Again, hope this helps, and hope I understood what you were looking for more clearly.

-Umbrae
0
 
LVL 5

Expert Comment

by:umbrae
ID: 12321358
As an addendum, you'd probably loop through the cookies array from your first cfhttp to pass the cookies most effectively with cfhttpparam.

-Umbrae
0
 

Author Comment

by:bptacek
ID: 12322572
Yeah, it seems like you are on the same page now :).  Anyways, I have tried passing the cookies manually.  However, there seems to be problems within problems here, because I tried to access the cookies by doing this:

CFHTTP.responseHeader.Set-Cookie

and

CFHTTP.responseHeader[Set-Cookie]

And I get an error that it can't find the "CFHTTP.responseHeader.Set" variable.  I assume this is the only way to loop through the cookies.  Plus, if I was able to get that "Set-Cookies", I am unsure as to how I would get the cookies and their values.  Is there a way to do this without parsing each line as a string?  Simple way to pull the cookie info out of the header?

Thanks
Ben
0
 
LVL 5

Expert Comment

by:umbrae
ID: 12322865
Try CFHTTP.responseHeader['Set-Cookie'], with the quotes. Also, as far as getting just the cookie data, I think a ReReplace(CFHTTP.responseHeader['Set-Cookie'][ArrayIndex],"([^;]*;.*)","\1;") would probably get the relevant data out of the string nicely.

-Umbrae
0
 
LVL 5

Accepted Solution

by:
umbrae earned 500 total points
ID: 12322874
Whoops. Bug!

REReplace(CFHTTP.responseHeader['Set-Cookie'][ArrayIndex],"([^;]*;).*","\1;")

is correct. Sorry bout that.

-Umbrae
0
 

Author Comment

by:bptacek
ID: 12323272
Whoo hoo!!!! it works.... my biggest downfall is good old regexp.  I have to get familiar with it.

Thanks umbrae!

Here is my loop for the second cfhttp to grab the cookies, just in case anyone else comes along the same problem:
============================================
      <cfloop from="1" to="16" index="num">
            <cfset cookstring = REReplace(CFHTTP.responseHeader['Set-Cookie'][num],"([^;]*).*","\1")>
            <cfhttpparam type="cookie" name="#ListGetAt(cookstring,1,'=')#" value="#ListGetAt(cookstring,2,'=')#">
      </cfloop>
============================================
I used 16 because I wasn't sure how to do a count on CFHTTP.responseHeader['Set-Cookie'].  I got an error on ArrayLen, so I just counted the number of cookies from the first cfhttp.

Thanks again, here are your points.

Ben
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

827 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