I have such a task, take data from one site (our corporate, not from the Internet, but I think it does not matter), I don’t have access to the database and said they don’t give it, you want to parse from the page. In general, in this topic for the first time, before the password only with xml or the whole html page is full))) And now you need to first go through authorization, then enter the desired person into the search engine id and pull out the result from there. Two days here I dig as it is possible to implement. Found several possible options. Using httpclient, but it gives me the passwords input page, it doesn't go any further. That is, I enter the page after entering the passwords and user name, but again sent to the page with the password request. Help me please.

import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import org.apache.http.HttpResponse; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; public class HttpBasicAuth { public static void main(String[] args) { try { DefaultHttpClient Client = new DefaultHttpClient(); Client.getCredentialsProvider().setCredentials(AuthScope.ANY,new UsernamePasswordCredentials("user1", "123456789")); HttpGet httpGet = new HttpGet("http://10.10.151.90/default.aspx"); HttpResponse response = Client.execute(httpGet); System.out.println("response = " + response); BufferedReader breader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuilder responseString = new StringBuilder(); String line = ""; while ((line = breader.readLine()) != null) { System.out.println(line); responseString.append(line); } breader.close(); String responseStr = responseString.toString(); System.out.println("responseStr = " + responseStr); } catch (IOException e) { e.printStackTrace(); } } } 
  • one
    What type of authorization on the site? If not BASIC, then you most likely need to use the POST method, and it is even more likely that this will use the HTTPS protocol. It would be nice to ask these questions to those who set you such a task. - a_gura
  • + Do not forget about Encode / Decode data, when sending and receiving a request. And I agree with the comment above - authorization requests in most cases are POST requests - Nuclominus
  • did as you advised, but did not resolve the question :( hashcode.ru/questions/334367/… - lp_4eva

0