Page 1 of 2
Question about RedirectResponse()...
Posted: Tue Jul 30, 2013 8:44 am
by terry_opie
Does RedirectResponse() only work to redirect to a page that is in the top level html directory? A assume no, since there isn't any indication otherwise in the Runtime Libraries pdf, but I just can't get anything else to work.
I've attempted just about every path combination that I can think of, but have yet to have any success redirecting to any file besides files in the top level directory. Based on what happens and what the inputs are, I would like to attempt to load pages from different subdirectories. Primarily to keep function separated.
I've tried the following:
Code: Select all
RedirectResponse( sock, "test.htm" ); // Works
RedirectResponse( sock, "normal/test.htm" ); // Doesn't Work
RedirectResponse( sock, "/normal/test.htm" ); // Doesn't Work
RedirectResponse( sock, "./normal/test.htm" ); // Doesn't Work
Any ideas or guidance as to what I'm doing wrong, or if its even possible are greatly appreciated!
Thank you.
Re: Question about RedirectResponse()...
Posted: Tue Jul 30, 2013 10:56 am
by pbreed
Can you access the file directly without the redirect?
IE is the problem the redirect or the visibility of the file you redirected to?
The redirect code is really simple...
void RedirectResponse( int sock, PCSTR new_page )
{
writestring( sock, "HTTP/1.0 302 Redirection\r\nLocation: " );
writestring( sock, new_page );
writestring( sock, "\r\n\r\n" );
}
Re: Question about RedirectResponse()...
Posted: Tue Jul 30, 2013 11:22 am
by terry_opie
Yes, I can access the file/url directly without the redirect. I saw the problem with Firefox, Safari, and Mobile Firefox... I make it a point not to use IE.

(unless I absolutely have to)
Is it required to use the full URL to the page? Or is it an absolute path? Since I was loading a file in the top level, by just using the file name, I figured that adding "./<dir name>/<file>", I'd be able to access it. But I've had no luck.
Re: Question about RedirectResponse()...
Posted: Tue Jul 30, 2013 12:51 pm
by pbreed
Should be just the relative path...
Is the redirect the ONLY thing you are doing?
IE you can't send data and then do a redirect, the redirect must be the first and only thing you do...
A wire shark capture of the transactions would abe a good place to start...
Re: Question about RedirectResponse()...
Posted: Tue Jul 30, 2013 1:21 pm
by terry_opie
pbreed wrote:Should be just the relative path...
Is the redirect the ONLY thing you are doing?
IE you can't send data and then do a redirect, the redirect must be the first and only thing you do...
A wire shark capture of the transactions would abe a good place to start...
Well, I've tried the relative path... I have listed above all of the different options I tried, but no dice.
I'm not sending data, but I am extracting data from the post, and then redirecting. I'm following pretty much the same code path that is being done in the HtmlFormPost example. Below is a snippet of my code...
Code: Select all
int postHandler ( int sock,
char *url,
char *pData,
char *rxBuffer )
{
int rc = 0;
iprintf("----- Processing Post -----\n");
iprintf("Post URL: %s\n", url);
iprintf("Post Data: %s\n", pData);
if( httpstricmp( url + 1, "SENDCANMSG" ) )
{
// Get the CAN Address
rc = ExtractPostData( "canaddr",
pData,
id,
MAX_POST_DATA_SIZE );
msg.id = strtoul( id, NULL, 16 );
RedirectResponse( sock, "test.htm" );
}
return 1;
}
Re: Question about RedirectResponse()...
Posted: Tue Jul 30, 2013 2:21 pm
by pbreed
That should work....
Look in the htmldata.cpp file and make sure the subdirectory is being included ....
Should have a table that looks like...
const HTML_FILE_RECORD file_record[xx]={
With the full paths listed.....
Really make sure your redirect has / not \ as it makes a difference....
Paul
Re: Question about RedirectResponse()...
Posted: Wed Jul 31, 2013 5:44 am
by terry_opie
This is the line from the htmldata.cpp:
Code: Select all
{"normal/test.htm",FilePointer50,0,eNoCompression,0, 0},
And the code listed above was directly from my code that I was trying... So, I'm sure that the slash vs. backslash was correct.
If there are any other things that I should check or try, please let me know. I've since moved everything to the top level directory and I'll play with it later... I have to start making some progress.
Re: Question about RedirectResponse()...
Posted: Wed Jul 31, 2013 8:25 am
by dciliske
Any chance you can post a network capture during the transaction?
Re: Question about RedirectResponse()...
Posted: Wed Jul 31, 2013 8:28 am
by terry_opie
dciliske wrote:Any chance you can post a network capture during the transaction?
From something like Wireshark?
Hopefully by the end of the week, yes, I could get that. I got pulled off onto something else higher priority.

Re: Question about RedirectResponse()...
Posted: Wed Jul 31, 2013 8:50 am
by pbreed
I'm sure the slash/backslash is correct in the htmldata file...
What you posted was from that file....
you also have to be sure the / \ is correct in the redirect.....
What you recently posted was not from that... (You did post these earlier, just don't know if they were copy and paste or typed here...)