Link to home
Start Free TrialLog in
Avatar of bptacek
bptacek

asked on

cfhttp + redirect not working

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
Avatar of bptacek
bptacek

ASKER

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
=============================================
Avatar of bptacek

ASKER

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?
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
Avatar of bptacek

ASKER

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
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
As an addendum, you'd probably loop through the cookies array from your first cfhttp to pass the cookies most effectively with cfhttpparam.

-Umbrae
Avatar of bptacek

ASKER

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
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
ASKER CERTIFIED SOLUTION
Avatar of umbrae
umbrae

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bptacek

ASKER

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