Package org.vietspider.net.client

Examples of org.vietspider.net.client.WebClient


*          nhudinhthuan@yahoo.com
* Nov 2, 2008
*/
public class GmailLogin {
  public static void main(String[] args) throws Exception {
    WebClient webClient = new WebClient();

    String homepage  = "http://mail.google.com/";
    webClient.setURL(homepage, new URL(homepage));

    HttpHost httpHost = webClient.createHttpHost(homepage);
    HttpGet httpGet = webClient.createGetMethod(homepage, "http://www.google.com");

    HttpResponse response = webClient.execute(httpHost, httpGet);
    HttpEntity entity = response.getEntity();

    System.out.println("Login form get: " + response.getStatusLine());
    if (entity != null) entity.consumeContent();

    System.out.println("Initial set of cookies:");
    DefaultHttpClient httpClient = (DefaultHttpClient) webClient.getHttpClient();
    List<Cookie> cookies = httpClient.getCookieStore().getCookies();
    if (cookies.isEmpty()) {
      System.out.println("None");
    } else {
      for (int i = 0; i < cookies.size(); i++) {
        System.out.println("- " + cookies.get(i).toString());
      }
    }

    HttpSessionUtils httpSession = new HttpSessionUtils(webClient, "ERROR");

    StringBuilder builder = new StringBuilder("https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=1k96igf4806cy&ltmpl=default&ltmplcache=2");
    builder.append('\n').append("your_username:your_password");

    httpSession.login(builder.toString(), "utf-8", new URL(homepage), homepage);

    httpGet = webClient.createGetMethod("http://mail.google.com/mail/", "http://gmail.com");
    response = webClient.execute(httpHost, httpGet);
    entity = response.getEntity();

    HttpResponseReader httpResponseReader = new HttpResponseReader();
    byte [] bytes = httpResponseReader.readBody(response);
    new DataWriter().save(new File("google_mail.html"), bytes);
View Full Code Here


* Nov 2, 2008
*/
public class YahooLogin {

  public static void main(String[] args) throws Exception {
    WebClient webClient = new WebClient();

    String homepage  = "http://mail.yahoo.com/";
    webClient.setURL(homepage, new URL(homepage));

    HttpHost httpHost = webClient.createHttpHost(homepage);
    HttpGet httpGet = webClient.createGetMethod(homepage, "http://www.yahoo.com");

    HttpResponse response = webClient.execute(httpHost, httpGet);
    HttpEntity entity = response.getEntity();

    System.out.println("Login form get: " + response.getStatusLine());
    if (entity != null) entity.consumeContent();

    System.out.println("Initial set of cookies:");
    DefaultHttpClient httpClient = (DefaultHttpClient) webClient.getHttpClient();
    List<Cookie> cookies = httpClient.getCookieStore().getCookies();
    if (cookies.isEmpty()) {
      System.out.println("None");
    } else {
      for (int i = 0; i < cookies.size(); i++) {
        System.out.println("- " + cookies.get(i).toString());
      }
    }

    HttpSessionUtils httpSession = new HttpSessionUtils(webClient, "ERROR");

    StringBuilder builder = new StringBuilder(homepage);
    builder.append('\n').append("your_username:your_password");

    httpSession.login(builder.toString(), "utf-8", new URL(homepage), homepage);

  httpGet = webClient.createGetMethod("http://my.yahoo.com", "http://www.yahoo.com");
    response = webClient.execute(httpHost, httpGet);
    entity = response.getEntity();


    HttpResponseReader httpResponseReader = new HttpResponseReader();
    byte [] bytes = httpResponseReader.readBody(response);
View Full Code Here

* Nov 2, 2008
*/
public class JavaNetLogin {

  public static void main(String[] args) throws Exception {
    WebClient webClient = new WebClient();

    String homepage  = "http://java.net/";
    webClient.setURL(homepage, new URL(homepage));

    HttpHost httpHost = webClient.createHttpHost(homepage);
    HttpGet httpGet = webClient.createGetMethod(homepage, "http://java.net/");

    HttpResponse response = webClient.execute(httpHost, httpGet);
    HttpEntity entity = response.getEntity();

    System.out.println("Login form get: " + response.getStatusLine());
    if (entity != null) entity.consumeContent();

    System.out.println("Initial set of cookies:");
    DefaultHttpClient httpClient = (DefaultHttpClient) webClient.getHttpClient();
    List<Cookie> cookies = httpClient.getCookieStore().getCookies();
    if (cookies.isEmpty()) {
      System.out.println("None");
    } else {
      for (int i = 0; i < cookies.size(); i++) {
        System.out.println("- " + cookies.get(i).toString());
      }
    }

    HttpSessionUtils httpSession = new HttpSessionUtils(webClient, "ERROR");

    StringBuilder builder = new StringBuilder(homepage);
    builder.append('\n').append("your_username:your_password");

    httpSession.login(builder.toString(), "utf-8", new URL(homepage), homepage);

    httpGet = webClient.createGetMethod("http://java.net/", "http://java.net/");
    response = webClient.execute(httpHost, httpGet);
    entity = response.getEntity();

    HttpResponseReader httpResponseReader = new HttpResponseReader();
    byte [] bytes = httpResponseReader.readBody(response);
    new DataWriter().save(new File("java_net.html"), bytes);
View Full Code Here

    URLUtils urlUtils = new URLUtils();
    address = urlUtils.createURL(loginUrl, address).trim();
    address = urlUtils.getCanonical(address);
   
    referer = loginUrl.toString();
    WebClient webClient = httpMethod.getWebClient();
    HttpHost httpHost = webClient.createHttpHost(address);
    HttpPost httpPost = webClient.createFormPostMethod(address, referer, params);
    HttpResponse response2 = httpMethod.execute(httpHost, httpPost);
   
    /*statusLine = response2.getStatusLine();
    statusCode = statusLine.getStatusCode();
    if(statusCode == HttpStatus.SC_MOVED_PERMANENTLY
        || statusCode == HttpStatus.SC_SEE_OTHER
        || statusCode == HttpStatus.SC_TEMPORARY_REDIRECT) {
      Header header = response2.getFirstHeader("Location");
      if(header != null
          && header.getValue() != null
          && !header.getValue().trim().isEmpty()) {
        System.out.println(header.getValue());
        try {
          response2 = httpMethod.execute(header.getValue(), null);
        } catch (Throwable e) {
          e.printStackTrace();
        }
        System.out.println(" da xong roi ");
      }
    }*/
   
//    System.out.println("status code "+ statusCode);
//    Header [] headers = response2.getAllHeaders();
//    for(Header header : headers) {
//      System.out.println(header.getName() + " : " + header.getValue());
//    }

    byte [] bytes = new byte[0];
//    org.vietspider.common.io.DataWriter writer = new org.vietspider.common.io.DataWriter();
//    java.io.File file = UtilFile.getFile("track/logs/", "login_" + Utils.toFileName(address));

    loginUtil.setPrevLogin(tokens);
    boolean error  = false;
    try {
      bytes = responseReader.readBody(response2);
    } catch (SocketException e) {
      LogService.getInstance().setMessage("WEB", e, e.toString());
      bytes = e.toString().getBytes();
      error = true;
    } catch (Exception e) {
      LogService.getInstance().setThrowable("WEB", e);
      bytes = e.toString().getBytes();
      error = true;
    }
   
    if(webClient.isLog()) {
      java.io.File file = UtilFile.getFile("track/logs/", "login_" + Utils.toFileName(address));
      LogService.getInstance().setMessage("WEB", null, "Login to: " +address);
      new org.vietspider.common.io.DataWriter().save(file, bytes);
    }
   
View Full Code Here

  }
 
  public static void main(String[] args) throws Exception  {
    URL url = new URL("http://news.google.com.vn/");
   
    WebClient webClient = new WebClient();
    webClient.setURL(null, url);
   
    NodePathParser pathParser = new NodePathParser();
    HTMLExtractor htmlExtractor = new HTMLExtractor();
   
    byte  [] bytes = download(webClient, "http://news.google.com.vn/");
View Full Code Here

TOP

Related Classes of org.vietspider.net.client.WebClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.