I'm thinking about making an app that gets data from a website. However this website can only be entered after entering a username and password. For example if you go to Example.com the browser would prompt you with something like "A username and password are being requested by example.com" and allow you to enter the username and password. How would I deal with this inside an app? I'm planning to use jsoup to collect the data once I get by the log-in. Thanks.
2 Answers
It depends a little how the login is implemented. If it is a HTTP POST request you could often do it in JSoup like this: Connection.Response response = Jsoup.connect(url).data("username", "user", "password", "pwd").method(Method.POST).execute()
. "username" and "password" are the names of the POST parameters that often correspond with HTML form fields. This is a working albeit simple approach. Sometimes (often) pages use additional security measures like Captchas or utilize Javascript for e.g. encryption of the password. Then you need to simulate that. But that depends on the specific site implementation.
If he site uses Basic HTTP authentication (your description of a popup sounds a little like it) you can find a solution here: Jsoup connection with basic access authentication .

- 1
- 1

- 11,559
- 1
- 42
- 50
-
Thanks! I think its basic HTTP authentication. I wasn't sure what it is was called or else I might have found that answer in a search :P – zkello Aug 10 '12 at 02:08
You could have a look on the java.net package or use HTTPUnit. It will help you to communicate with the WebServer via HTTP like Methods.

- 1,245
- 1
- 10
- 22