package com.codigg.farmer;
 
import java.io.InputStream;
import java.util.List;
 
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.DefaultHttpClient;
 
/**
 * 农场登录演示代码
 * @author www.codigg.com
 *
 */
public class Test {
 
public static void main(String[] args) throws Exception {
// 登录,其中后面的密码是www.codigg.com加密后的结果
testLogin("www.codigg.com", "4b1f0bdd013adac8b11cae3f98cc7f27");
}
 
public static void testLogin(String username, String password)
throws Exception {
 
// 创建HttpClient对象
DefaultHttpClient httpclient = new DefaultHttpClient();
 
// 登录,其中密码是已经加密后的字符串,其它参数都可以伪造,不用理会
HttpGet getLogin = new HttpGet(
"http://passport.sohu.com/sso/login.jsp?userid="
+ username
+ "&password="
+ password
+ "&appid=1062&persistentcookie=1"
+ "&s=1344036327984&b=5&w=1280&pwdtype=1");
 
HttpResponse response = httpclient.execute(getLogin);
HttpEntity entity = response.getEntity();
if (entity != null)
entity.consumeContent();
 
// 此时就已经有登录后的会话了,然后访问农场页面
HttpGet getFarm = new HttpGet("http://bai.sohu.com/app/farm/");
HttpResponse response2 = httpclient.execute(getFarm);
HttpEntity entity2 = response2.getEntity();
InputStream input = entity2.getContent();

解决方案 »

  1.   

    package com.codigg.farmer;
     
    import java.io.InputStream;
    import java.util.List;
     
    import org.apache.commons.io.IOUtils;
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.cookie.Cookie;
    import org.apache.http.impl.client.DefaultHttpClient;
     
    /**
     * 农场登录演示代码
     * @author www.codigg.com
     *
     */
    public class Test {
     
    public static void main(String[] args) throws Exception {
    // 登录,其中后面的密码是www.codigg.com加密后的结果
    testLogin("www.codigg.com", "4b1f0bdd013adac8b11cae3f98cc7f27");
    }
     
    public static void testLogin(String username, String password)
    throws Exception {
     
    // 创建HttpClient对象
    DefaultHttpClient httpclient = new DefaultHttpClient();
     
    // 登录,其中密码是已经加密后的字符串,其它参数都可以伪造,不用理会
    HttpGet getLogin = new HttpGet(
    "http://passport.sohu.com/sso/login.jsp?userid="
    + username
    + "&password="
    + password
    + "&appid=1062&persistentcookie=1"
    + "&s=1344036327984&b=5&w=1280&pwdtype=1");
     
    HttpResponse response = httpclient.execute(getLogin);
    HttpEntity entity = response.getEntity();
    if (entity != null)
    entity.consumeContent();
     
    // 此时就已经有登录后的会话了,然后访问农场页面
    HttpGet getFarm = new HttpGet("http://bai.sohu.com/app/farm/");
    HttpResponse response2 = httpclient.execute(getFarm);
    HttpEntity entity2 = response2.getEntity();
    InputStream input = entity2.getContent();