Another RedirectResponse() issue...

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

Another RedirectResponse() issue...

Post by terry_opie »

Now that I understand how RedirectResponse() is working based on where its being called from and the relative paths to where I want the redirect to happen, I'm seeing something else that I can't explain. I'm hoping someone else has seen this or has a solution.

From html in a given directory, I submit a form. After parsing the form data, I then call RedirectResponse() to redirect to the same file that the form was submitted from. For example. I start with /html/somedirectory/test.htm, and then call RedirectResponse( sock, "test.htm" );

From within Firebug, I see that the post and response seem to look ok.


Post String:

Code: Select all

http://192.168.50.61/mobile/sendcanmsg?byte0=11&byte1=22&byte2=33&byte3=44&byte4=55&byte5=66&byte6=77&byte7=30&canaddr=111

Redirect Request:

Code: Select all

GET /mobile/test.htm HTTP/1.1
Host: 192.168.50.61
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0
Accept: text/html, */*; q=0.01
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://192.168.50.61/mobile/test.htm
X-Requested-With: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
But what I'm seeing on each browser that I try (Firefox 22.0 - desktop, Mobile Firefox 22.0, and Safari), is that the browser never actually loads <nb ip>/mobile/test.htm. It continues to stop at <nb ip>/mobile/sendcanmsg "sendcanmsg" is the form id that is being submitted.

Just in case its helpful, I've attached a wireshark capture of the POST request and subsequent redirect request. The request starts with frame 49. Save, then remove the .txt from the file. It wouldn't let me add it as is.

Any ideas? Any help is appreciated.
Thank you!
Attachments
nburn_redirect_capture.pcapng.txt
(39.93 KiB) Downloaded 423 times
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Re: Another RedirectResponse() issue...

Post by terry_opie »

After more experimenting, I'm even more confused... The page loads and looks as if it loads correctly. I see the layout and form/buttons I expect, but none of my scripts are running.

I just happened to look at the page source to see what it had loaded, and found this:

Code: Select all

<HEAD><TITLE>404 Not Found</TITLE></HEAD>
<BODY><H1>404 Not Found</H1>
The requested URL mobile/sendcanmsg was not found on this server.<BR>
</BODY>

So, then I tried to send it to a different page. I created sent.htm, and changed my RedirectResponse() to redirect to sent.htm. I see the output of what sent.htm should look like in the browser, but when viewing the source of the page, again I see what is pasted above.

It seems like after the redirect it is trying to redirect somewhere else again... Not to mention that when the browser stops on the <nb ip>/mobile/sendcanmsg, it breaks all navigation, since that isn't a real file/page that it can load.

Firebug/Wireshark aren't showing anything obvious. I'm at a loss... Any ideas?

Thanks.
User avatar
dciliske
Posts: 624
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: Another RedirectResponse() issue...

Post by dciliske »

Looking through the capture, I can't find anything going wrong.

Something's bizzare here; would it be possible to upload the application image? (s19's and pcaps have been added to the approved extensions list)

Also, thumbs up for useful related info (packet dump, etc.).

-Dan
Dan Ciliske
Project Engineer
Netburner, Inc
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Re: Another RedirectResponse() issue...

Post by terry_opie »

Hi Dan... Yes, Please find the .s19 file attached. I attached both the _APP version and without since I wasn't sure which one you'd need.

Details to recreate:
  • Load IP address of where this is installed.
  • Set address directly to <nb ip>/mobile/test.htm.
  • Click the Submit button (Button text: Send CAN Msg)
  • Look at the address bar of your browser. It should be redirected back to the original test.htm page.
The address I submit the form from: <nb ip>/mobile/test.htm
The address in the browser window after submitting: <nb ip>/mobile/sendcanmsg

One other oddity, is that I actually have 2 sites in this code. One for desktop usage, and another for mobile devices. The mobile device code is where the issue is seen. The desktop site (<nb ip>/normal/test.htm) is working and redirecting correctly. So, now I'm wondering if some of the jQuery stuff is interfering with the redirect... But if it is, it isn't showing up anywhere.

No problem on the packet dump... I wanted to be sure I looked at all possibilities before I started asking for help. I appreciate the help. Let me know if you have any other questions or need anything from me. This definitely has me puzzled...
Thank you!
Attachments
Reflex_APP.s19
(2.24 MiB) Downloaded 381 times
Reflex.s19
(3.73 MiB) Downloaded 403 times
User avatar
dciliske
Posts: 624
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: Another RedirectResponse() issue...

Post by dciliske »

OK, here's where things get weird. It works for me, but when the redirect occurs, the address bar still has the address as

Code: Select all

http://192.168.1.164/mobile/sendcanmsg
Actually, here's a weird thing: the normal test page displays the results of the AJAX query, but the mobile page doesn't change.

Something seems off here... I'll have to look at the headers sent back by Apache or lighttpd to see how things compare.

-Dan
Dan Ciliske
Project Engineer
Netburner, Inc
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Re: Another RedirectResponse() issue...

Post by terry_opie »

dciliske wrote:OK, here's where things get weird. It works for me, but when the redirect occurs, the address bar still has the address as

Code: Select all

http://192.168.1.164/mobile/sendcanmsg
Actually, here's a weird thing: the normal test page displays the results of the AJAX query, but the mobile page doesn't change.

Something seems off here... I'll have to look at the headers sent back by Apache or lighttpd to see how things compare.

-Dan
It works for me when the page first loads, but usually not after submitting the form. And if it did work consistently, I still couldn't live with it since the address bar shows the sendcanmsg address it completely messes up navigation using forward/back buttons and the like.

I believe that the page does actually change. I was watching requests via firebug (and also saw it in the wireshark log) that the page is redirected, then fetched again and received...

I just don't understand why the address doesn't change... And why the page source shows "404 Not Found".
User avatar
dciliske
Posts: 624
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: Another RedirectResponse() issue...

Post by dciliske »

This is starting to get a little deep, can you go ahead and open a support ticket?

-Dan
Dan Ciliske
Project Engineer
Netburner, Inc
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Re: Another RedirectResponse() issue...

Post by terry_opie »

dciliske wrote:This is starting to get a little deep, can you go ahead and open a support ticket?

-Dan
Thanks Dan... I've opened ticket# 33152.
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Re: Another RedirectResponse() issue...

Post by terry_opie »

Well, it seems that somehow the jQuery stuff I was using on my pages were causing havoc with how the post requests were actually made. I still haven't found the root cause of that yet, but I am still looking.

I have found a workaround, in case anyone is interested. Its pretty hackish, but it does what I need it to do.

For the submit button on the form (via POST), I have an onclick event to call startURL(). The following is the javascript that gets called from that:

Code: Select all

        <script>
            function startURL()
            {
                setTimeout( 'loadURL()', 250 );
            }

            function loadURL()
            {
                window.location.href = "test.htm";
            }
        </script>
Essentially call the function and wait 250ms to give the form time to send the POST request, then set the page href so the page loads. This takes place of the RedirectResponse() from the C code.

Again, this is hackish and I'm not thrilled with it, but it works...
User avatar
Forrest
Posts: 289
Joined: Wed Apr 23, 2008 10:05 am

Re: Another RedirectResponse() issue...

Post by Forrest »

Another solution is to use ajax to send the form post

I used jquery to select the form (you would need to add id="canmsgform" to the <form> statement to allow the selector to work), then overrode the submit functionality of the form. By returning false, the html submit is never performed. The end result is the form in submitted without having to refresh or reload the page. Because of this, you are never sent to the url sendcanmsg.

This code would be placed at the end of your html body.

Code: Select all

        <script> 
        $('#canmsgform').submit(function() {
            $.ajax({
                type: 'POST',
                url: 'sendcanmsg',
                data: $(this).serializeArray(),
            });
            return false;
        }); 
        </script>
Forrest Stanley
Project Engineer
NetBurner, Inc

NetBurner Learn Articles: http://www.netburner.com/learn
Post Reply