Reputation: 171
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?
ANY help would be apreciated.
Upvotes: 3
Views: 794
Reputation: 28418
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.
Upvotes: 2
Reputation: 700
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
Upvotes: 0