K
konrad-g
Hello,
here's my problem. I'm writing a crawler which needs to access password
protected ASP pages. I know the password protected URL, but accessing
it without login invokes login screen, which (after logging in)
redirects me back to the page. I know URL of that login page too.
Here's my code:
/************** Code begins *************/
URL url = new URL( urlString );
HttpURLConnection c = (HttpURLConnection)url.openConnection();
c.setRequestMethod("POST");
c.setDoInput(true);
c.setDoOutput(true);
c.setUseCaches(false);
OutputStream urlOut = c.getOutputStream();
urlOut.write(("LoginControl1:txtEmail="+URLEncoder.encode("login")+"&LoginControl1:txtPassword="+URLEncoder.encode("pass")).getBytes());
InputStream content = (InputStream)c.getInputStream();
BufferedReader in = new BufferedReader (new InputStreamReader
(content));
String line;
while ((line = in.readLine()) != null) System.out.println (line);
/************** Code ends *************/
I tried to set up urlString for two values. First of them is login
page, which (after logging in) should redirect me to desired page.
Using it ends up with "Server redirected too
many times" exception. The second option is using desired page's URL
as urlString - but in this case final "while" loop produces login
screen instead of desired page.
Any clues?
Thanks in advance,
Konrad Garus
here's my problem. I'm writing a crawler which needs to access password
protected ASP pages. I know the password protected URL, but accessing
it without login invokes login screen, which (after logging in)
redirects me back to the page. I know URL of that login page too.
Here's my code:
/************** Code begins *************/
URL url = new URL( urlString );
HttpURLConnection c = (HttpURLConnection)url.openConnection();
c.setRequestMethod("POST");
c.setDoInput(true);
c.setDoOutput(true);
c.setUseCaches(false);
OutputStream urlOut = c.getOutputStream();
urlOut.write(("LoginControl1:txtEmail="+URLEncoder.encode("login")+"&LoginControl1:txtPassword="+URLEncoder.encode("pass")).getBytes());
InputStream content = (InputStream)c.getInputStream();
BufferedReader in = new BufferedReader (new InputStreamReader
(content));
String line;
while ((line = in.readLine()) != null) System.out.println (line);
/************** Code ends *************/
I tried to set up urlString for two values. First of them is login
page, which (after logging in) should redirect me to desired page.
Using it ends up with "Server redirected too
many times" exception. The second option is using desired page's URL
as urlString - but in this case final "while" loop produces login
screen instead of desired page.
Any clues?
Thanks in advance,
Konrad Garus