httpclient(校内网)

httpclient(校内网),大家帮忙看看我的httpclient怎么发不到对方站内信呢?博客倒是能发,但是就是站内这里出问题~

Java code

    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(); } }
 

相关推荐