使用Java应用程序登录hotfile

时间:2011-02-19 11:32:13

标签: java apache-httpclient-4.x

我想登录Hotfile并使用我的Java应用程序进行文件保存; 我使用Apache。

public static void main(String[] args) throws Exception {

    DefaultHttpClient httpclient = new DefaultHttpClient();

    HttpGet httpget = new HttpGet("http://www.hotfile.com/");

    HttpResponse response = httpclient.execute(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:");
    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());
        }
    }

    HttpPost httpost = new HttpPost("http://www.hotfile.com/index.php");

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();

    nvps.add(new BasicNameValuePair("user", "myuser"));
    nvps.add(new BasicNameValuePair("pass", "mypass"));
    nvps.add(new BasicNameValuePair("returnto", "/"));
    httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

    response = httpclient.execute(httpost);

    System.out.println("Response " + response.toString());
    entity = response.getEntity();

    System.out.println("Login form get: " + response.getStatusLine());
    if (entity != null) {
        InputStream is = entity.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String str = "";
        while ((str = br.readLine()) != null) {
            System.out.println("" + str);
        }
    }

    System.out.println("Post logon cookies:");
    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());
        }
    }
    httpclient.getConnectionManager().shutdown();
}

但它不起作用。我如何登录这些网站?

1 个答案:

答案 0 :(得分:1)

使用他们的API,mate,http://api.hotfile.com/

示例:http://api.hotfile.com/?action=getuserinfo&username=myuser&password=mypass

示例返回结果:is_premium=0&hotlink_traffic_kb=70