package com.lihan.dao;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.PostMethod;public final class LoginXiaonei {
    public static void main(String[] a)
    {
        HttpClient client=new HttpClient();
        PostMethod post=new PostMethod("http://login.xiaonei.com/Login.do");
        post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        client.getParams().setContentCharset( "utf-8 "); 
        client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
        NameValuePair[] data=
        {
            new NameValuePair("email","********@163.com"),
            new NameValuePair("password","******")
        };
        post.setRequestBody(data);
        try {
            client.executeMethod(post);
            Cookie [] cookies=client.getState().getCookies();
            InputStream stream=post.getResponseBodyAsStream();
            writeStream(stream);
            stream.close();
            post.releaseConnection();          
            post=new PostMethod("http://msg.xiaonei.com/message/send.do");
            post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            data=new NameValuePair[]{
                new NameValuePair("ids[]","227949683")  ,
                new NameValuePair("subject","hahahahaha")  ,
                new NameValuePair("message","0")  ,
            };
            post.setRequestBody(data);
            client.executeMethod(post);
            stream=post.getResponseBodyAsStream();
            writeStream(stream);
            stream.close();
            post.releaseConnection();
        }catch (HttpException ex) {
            Logger.getLogger(XiaoNeiBlog.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(XiaoNeiBlog.class.getName()).log(Level.SEVERE, null, ex);
        } 
        
    }
    private static void writeStream(InputStream stream) throws IOException
    {
        BufferedReader reader=new BufferedReader(new InputStreamReader(stream,"utf-8"));
        String line=null;
        for(line=reader.readLine();line!=null;line=reader.readLine())
        {
            System.out.println(line);
        }
        reader.close();
    }
}

解决方案 »

  1.   

    可能是人家有http安全机制,或者数据包加过密钥
      

  2.   


    data=new NameValuePair[]{
                    new NameValuePair("ids[]","227949683")  ,
                    new NameValuePair("subject","hahahahaha")  ,
                    new NameValuePair("message","0")  ,
                };我不知道你为什么以为那里应该是ids[],实际上,应该是ids,
    http://dev.xiaonei.com/wiki/XN.UI.multiFriendSelector
    你看看这个网页,是校内网的开发日志,说到,当你选中一个用户的时候,是生成了一个hidden字段,其name为ids.我没有做试验,只是根据理解。