模拟输入用户名和口令进行登录 java应用程序直接进入126邮箱,失败了!

puhongchun 2009-06-04 02:46:07
我的代码如下:



static final String LOGON_SITE = "localhost";//我的服务器地址

static final int LOGON_PORT = 8080;//我的服务器端口


public static void main(String[] args) throws IOException {
HttpClient client = new HttpClient();

client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);



//模拟登录页面
PostMethod post = new PostMethod("http://www.126.com");

NameValuePair name = new NameValuePair("user", "xxxxx");

NameValuePair pass = new NameValuePair("password", "xxxxx");

post.setRequestBody(new NameValuePair[]{name,pass});

int status = client.executeMethod(post);

System.out.println(post.getResponseBodyAsString());

post.releaseConnection();

CookieSpec cookiespec = CookiePolicy.getDefaultSpec();

Cookie[] cookies = cookiespec.match(LOGON_SITE, LOGON_PORT, "/", false, client.getState().getCookies());

if (cookies.length == 0) {

System.out.println("None");

} else {

for (int i = 0; i < cookies.length; i++) {

System.out.println(cookies[i].toString());

}

}

GetMethod get = new GetMethod("http://www.126.com");

client.executeMethod(get);

System.out.println(get.getResponseBodyAsString());

get.releaseConnection();

}



在控制台显示的还是www.126.com 登录页面的html脚本:















...全文
202 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
YuLimin 2009-06-21
  • 打赏
  • 举报
回复
1、可能126.com限制了远程访问

2、增request Header看看。

2,633

社区成员

发帖
与我相关
我的任务
社区描述
WebSphere 是 IBM 的软件平台。它包含了编写、运行和监视全天候的工业强度的随需应变 Web 应用程序和跨平台、跨产品解决方案所需要的整个中间件基础设施,如服务器、服务和工具。
社区管理员
  • WebSphere社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧