Question about RedirectResponse()...

Discussion to talk about software related topics only.
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Question about RedirectResponse()...

Post 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.
User avatar
pbreed
Posts: 1091
Joined: Thu Apr 24, 2008 3:58 pm

Re: Question about RedirectResponse()...

Post 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" );
}
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Re: Question about RedirectResponse()...

Post 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.
User avatar
pbreed
Posts: 1091
Joined: Thu Apr 24, 2008 3:58 pm

Re: Question about RedirectResponse()...

Post 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...
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Re: Question about RedirectResponse()...

Post 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;
}
User avatar
pbreed
Posts: 1091
Joined: Thu Apr 24, 2008 3:58 pm

Re: Question about RedirectResponse()...

Post 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
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Re: Question about RedirectResponse()...

Post 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.
User avatar
dciliske
Posts: 624
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: Question about RedirectResponse()...

Post by dciliske »

Any chance you can post a network capture during the transaction?
Dan Ciliske
Project Engineer
Netburner, Inc
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Re: Question about RedirectResponse()...

Post 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. :(
User avatar
pbreed
Posts: 1091
Joined: Thu Apr 24, 2008 3:58 pm

Re: Question about RedirectResponse()...

Post 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...)
Post Reply