3

I need to download an html file from a webserver. But to do this i need to log in to the website. The login form is located into an iframe an it is neither allowed nor it seems to be possible to access it directely.(->no POST)

Thats why i use javascript to fill out and submit the form automativally within my app. But now i need to download this file in the background (as service). Unfortunally services do not have an UI,so it seems i cant use a webview, like i did before.

So here is my question: is it possible to use a webview inside a service? Is there any alternative how i can interact with a website using javascript? Or is there any other possibility to log in automatically to the website?

The website is: https://light.dsbcontrol.de/DSBlightWebsite/(S(jlbbytzvocksc4v2i30gtjli))/Homepage/Player.aspx?ID=b4457c67-24a2-446f-af41-810fba7f723d&MaxWidth=1010&MaxHeight=607&MyDate=0

ANY help would be apreciated.

incognym
  • 171
  • 2
  • 2
  • 10

2 Answers2

2

If I am not missing anything when you press "weiter" buttons (I guess this is a "Submit" button), then here is what happens:

POST /DSBlightWebsite/(S(jlbbytzvocksc4v2i30gtjli))/Homepage/IFrame.aspx?ID=b4457c67-24a2-446f-af41-810fba7f723d&Width=937&Height=530&MyDate=0 HTTP/1.1
Host: light.dsbcontrol.de
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: https://light.dsbcontrol.de/DSBlightWebsite/(S(jlbbytzvocksc4v2i30gtjli))/Homepage/IFrame.aspx?ID=b4457c67-24a2-446f-af41-810fba7f723d&Width=937&Height=530&MyDate=0
Content-Type: application/x-www-form-urlencoded
Content-Length: 273

__VIEWSTATE=%2FwEPDwULLTEwODU4OTkxMzRkZGl5uRxMYz320dUnYalV0rRm4KBLu%2F%2FmncdSoRUaM2Cr&__EVENTVALIDATION=%2FwEWBALArNzjCQK10rnVAQLLus%2B1BQLpvY%2BZD1oB3Xt3JbIIPV05vCoiVbXiTq5FzSyFDPswYprWZto4&ctl02%24txtBenutzername=sdfasf&ctl02%24txtPasswort=asfsad&ctl02%24btnLogin=weiter

As you can see this is a application/x-www-form-urlencoded POST to light.dsbcontrol.de/DSBlightWebsite/(S(jlbbytzvocksc4v2i30gtjli))/Homepage/IFrame.aspx?ID=b4457c67-24a2-446f-af41-810fba7f723d&Width=937&Height=530&MyDate=0 with a set of params:

__VIEWSTATE=/wEPDwULLTEwODU4OTkxMzRkZGl5uRxMYz320dUnYalV0rRm4KBLu//mncdSoRUaM2Cr
__EVENTVALIDATION=/wEWBALArNzjCQK10rnVAQLLus+1BQLpvY+ZD1oB3Xt3JbIIPV05vCoiVbXiTq5FzSyFDPswYprWZto4
ctl02$txtBenutzername=sdfasf
ctl02$txtPasswort=asfsad
ctl02$btnLogin=weiter

So I belive you can use HttpClient to make such a POST directly without the need to use JavaScript/WebView. You just need to use your params instead. However I realize it could be unclear what some params mean, but that might be explained at the web API documentation. If there is no web API documentation, then I suspect such approach may not work since you may just not know what values to pass as those params.

Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91
  • I already tryed this method. It seems to be not possible to access iframe.aspx directly, what means i cant post anything to it. Thats why i used javascript.by the way, there is no documentation. – incognym Jun 14 '12 at 08:03
  • OK! i found a Solution how i can send a POST! The refferer must be the exactly same url like the one i send the POST to, and the parameters VIEWSTATE & EVENTVALIDATION (can be found on the formular page) must be sended exactly like found in the login page. Its complicated, butthats a way i works. Thanks for showing me the right direction. Now i can finish my app. – incognym Jun 14 '12 at 17:43
  • @incognym: Congratulations! I'm glad I was helpful at least in pointing to the right direction. Feel free to express your gratitude by voting up the answer. :) – Vit Khudenko Jun 14 '12 at 21:39
0

If you need to access that file I believe an authentication header may be required. This thread may help you how to do form based auth in android: Android - Form based authentication

Community
  • 1
  • 1
VCODE
  • 535
  • 5
  • 19