2

I'm developing a java application for a GPRS modem (Siemens TC65). I call several times a method to do a HttpConnection to different URLs. Sometimes it works fine but sometimes I get redirected by my operator (HTTP code 302). I follow the URL provided in the Location header it returns 200 but it's not the page that I want.

If I use the SIM card in a gsm pen and access with a browser, sometimes the same redirect occurs but i eventually reach the desired page. The problem is the modem doesn't execute Javascript, so I analysed what the javascript does and the procedure is the following:

page1 -> page2 -> page3 -> desired page

Page1 and page2 do some base64 coding of the URL and parameters, page3 is a .aspx. So everytime I get a redirection I encode64 my URL and send to the .aspx page, the .aspx page returns 302 with the desired page decoded in the Location header. It even returns a cookie with ASP.NET_SessionId which I save and send in the next request.

But even if i do all of this and follow the URL returned by the .aspx (which is the same as I begin with) it just starts from the beginning and I get an endless loop of redirects.

I can post the code but I don't think it has any problem since it works fine, sometimes... The problem is the successive redirects by the operator and not running a browser.

Anything i should do differently when trying to follow a redirection from an aspx server?

Anyone had any similar problem? I would greatly appreciate any help.

Thanks in advance! Hugo

Hugo Rocha
  • 537
  • 5
  • 23
  • 1
    I'm confused. Is the ability to run JavaScript significant or not? Also, have you tried capturing the request headers from a browser request that works and comparing them to an `HttpConnection` request that goes into an infinite loop? One possibility (just a guess) is that it is sniffing the User-Agent and changing its behavior. There may be something else in the headers as well. – Charles Forsythe Apr 02 '13 at 16:18
  • Sorry for the long post, I know it looks kind of confusing. Javascript is important because the redirection from page2 to page3 is done by javascript besides the base64 encoding. So i just replicated the process in my program and requested page3. Yes I checked the headers in the browser I used the same at least the ones I thought were important. I even tried to use the no-transformation header, and if my operator honored it i guess there shouldn't be any encoding at all. The User-Agent I used what I guess is the standard for a j2me, I got the system profile and configuration. – Hugo Rocha Apr 03 '13 at 07:56
  • 1
    Can you post the URLs of these pages? I'm guessing -- just guessing -- that different redirects might occur because the site might think you are a mobile browser (based on your User Agent). That's why that might be important, but it's just a guess. – Charles Forsythe Apr 03 '13 at 12:59
  • Yes but I also tried with different User Agents and happens the same. Also tried in a browser and the redirects are ok. Page1=redirect.static.kanguru.pt/Campanhas/redirect1.html Page2=http://redirect.static.kanguru.pt/Campanhas/redirect2.html?final_url=aHR0cDovL3d3dy5nb29nbGUuY29t (to google) Page3=http://redirect.kanguru.pt/RedirectKanguru/RedirectPage.aspx?final_url=aHR0cDovL2dvb2dsZS5jb20= (to google) – Hugo Rocha Apr 03 '13 at 15:04
  • OK, so when I click on Page 3 in my browser I go to Google. Is page3 the page that creates an infinite loop? – Charles Forsythe Apr 03 '13 at 16:17
  • Yes, after page3 I get 302 with the URL from, this case, google, but if I tried to do a connection to google after that i got redirected to page1 again. Funny thing is in the browser if I only visit page3 it works, but in the modem it doesnt, I have to request the three pages in the right sequence. Thanks for your help, I'm new to posting in stackoverflow is there anyway i can give you reputation? – Hugo Rocha Apr 03 '13 at 16:34

1 Answers1

1

I managed to make it work.

What I was doing is replacing the javascript in page2 by my own code in my program, since the modem can't run javascript. And used the result and sent it to page3. This is fine but I actually wasn't making a HTTP request to page2.

If I request the three pages in the right sequence, replicating the functions that the javascript did in my own code and save the cookies, after page3 I receive a redirect to the desired web page and doesn't redirect again like it used to. I figured since I did everything page2 did I really didn't need to make a request and just skipped to page3. But for some reason I do, I dunno why, maybe the asp session actually starts on that page and doesn't show on the page source code or the server monitors the page request. And I didn't even understand why the operator needs to do this, I think it might even break HTTP connections from old cellphones cause it isn't really designed for devices that can't run javascript.

Next time I will just use a different operator =p

Thanks to Charles Forsythe for the tips and help.

Hugo Rocha
  • 537
  • 5
  • 23