0

我正在尝试登录 meetme.com,但我不知道该怎么做。我正在使用来自 Apache 的 HttpComponents。当我运行下面的代码时,我得到一个 200 的响应代码。我有一个两部分的问题。

1.我如何登录www.meetme.com
2.假设用户输入了错误的密码,我如何从响应中知道是否成功登录?

import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.NameValuePair;

class Me {
    private final String loginurl = "http://www.meetme.com";
    private ArrayList<NameValuePair> loginParameters;
    HttpPost post;
    HttpClient client;

    public Me(){
        try{
            client = new DefaultHttpClient();
            setLoginParameters();

            post = new HttpPost(loginurl);
            post.setEntity(new UrlEncodedFormEntity(loginParameters));
            HttpResponse response = client.execute(post);

            //How do can I know if the login was successful?
            System.out.println(response.getStatusLine());
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    private void setLoginParameters(){
        loginParameters = new ArrayList<NameValuePair>(1);
        loginParameters.add(new BasicNameValuePair("username","USERNAME_HERE"));
        loginParameters.add(new BasicNameValuePair("password","PASSWORD_HERE"));
        loginParameters.add(new BasicNameValuePair("quicklogin","1"));
        loginParameters.add(new BasicNameValuePair("currentLocale","en-US"));
    }

    public static void main(String args[]){
        new Me();
    }
}
4

0 回答 0