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(); } }
相关推荐
84487600 2020-08-16
似水流年梦 2020-08-09
knightwatch 2020-07-26
fengchao000 2020-06-16
标题无所谓 2020-06-14
sicceer 2020-06-12
yanghui0 2020-06-09
yanghui0 2020-06-09
创建一个 HttpClient 实例,这个实例需要调用 Dispose 方法释放资源,这里使用了 using 语句。接着调用 GetAsync,给它传递要调用的方法的地址,向服务器发送 Get 请求。
wanghongsha 2020-06-04
jiaguoquan00 2020-05-26
zhaolisha 2020-05-16
wanghongsha 2020-05-05
wanghongsha 2020-04-14
knightwatch 2020-04-11
hygbuaa 2020-03-27
zergxixi 2020-03-24