java.net.URL 模拟用户登录网页并维持session
java.net.URL 模拟用户登录网页并维持session
半成品,并非完全有用
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL; public class SessionHolder {
public static void main(String[] args) throws Exception {
URL url = new URL("http://192.168.1.147:144/platformproxy/j_spring_security_check");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);// 允许连接提交信息
connection.setRequestMethod("POST");// 网页提交方式“GET”、“POST”
connection.setRequestProperty("User-Agent", "Mozilla/4.7 [en] (Win98; I)");
StringBuffer sb = new StringBuffer();
// sb.append("username=admin");
// sb.append("&password=admin");
sb.append("j_username=09000001");
sb.append("&j_password=zsinsgooda");
OutputStream os = connection.getOutputStream();
os.write(sb.toString().getBytes());
os.close();
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String responseCookie = connection.getHeaderField("Set-Cookie");// 取到所用的Cookie
System.out.println("cookie:" + responseCookie);
String line = br.readLine();
while (line != null) {
System.out.println(new String(line.getBytes()));
line = br.readLine();// 打出登录的网页
}
// acces
URL url1 = new URL("网页的登录后的页面");
HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection();
connection1.setRequestProperty("Cookie", responseCookie);// 给服务器送登录后的cookie
BufferedReader br1 = new BufferedReader(new InputStreamReader(connection1.getInputStream()));
String line1 = br1.readLine();
while (line1 != null) {
System.out.println(new String(line1.getBytes()));
line1 = br1.readLine();
}
}
}
引用自:http://blog.csdn.net/zgrjkflmkyc/article/details/9150511
java.net.URL 模拟用户登录网页并维持session的更多相关文章
- java.net.URL 模拟用户登录网页并维持session【转】
java.net.URL 模拟用户登录网页并维持session 半成品,并非完全有用 import java.io.BufferedReader; import java.io.InputStream ...
- 运用String类实现一个模拟用户登录程序
package Test; import java.util.Scanner; // 模拟用户登录程序 // 思路: // 1.用两个String类分别接收用户名和密码 // 2.判断输入的用户名和密 ...
- Redis缓存Mysql模拟用户登录Java实现实例[www]
Redis缓存Mysql模拟用户登录Java实现实例 https://jingyan.baidu.com/article/09ea3ede1dd0f0c0aede3938.html redis+mys ...
- python用scrapy模拟用户登录
scrapy模拟登录 关注公众号"轻松学编程"了解更多. 注意:模拟登陆时,必须保证settings.py里的COOKIES_ENABLED(Cookies中间件) 处于开启状态 ...
- xpath技术解析xml以及案例模拟用户登录效果
问题:当使用dom4j查询比较深的层次结构的节点(标签,属性,文本),比较麻烦!!! xpath就在此情况下产生了--主要是用于快速获取所需的[节点对象]. 在dom4j中如何使用xPath技术 1) ...
- jdbc封装模拟用户登录
dao层 接口 package com.qu.dao; public interface ILoginDAO { /** * 模拟用户登录 * 验证用户名 密码是否正确 * select * from ...
- scrapy模拟用户登录
scrapy框架编写模拟用户登录的三种方式: 方式一:携带cookie登录,携带cookie一般请求的url为登录后的页面,获取cookie信息应在登录后的页面获取,cookie参数应转成字典形式 # ...
- Java 之 cookie 记住用户登录时间案例
需求: 1. 访问一个Servlet,如果是第一次访问,则提示:您好,欢迎您首次访问. 2. 如果不是第一次访问,则提示:欢迎回来,您上次访问时间为:显示时间字符串 分析: 1. 可以采用Cookie ...
- python 初学习 模拟用户登录
#!/usr/bin/env python#coding:utf-8''' 2017年8月19日 模拟用户登录,userfile 文件保存字典 用户名,和密码 sorryname 文件保存字典 登录过 ...
随机推荐
- C++实现不能被继承的类——终结类 分类: C/C++ 2015-04-06 14:48 64人阅读 评论(0) 收藏
1. 问题 C++如何实现不能被继承的类,即终结类.Java中有final关键字修饰,C#中有sealed关键字修饰,而C++目前还没有类似的关键字来修饰类实现终结类,需编程人员手动实现. ...
- 各种Linux发行版本优缺点对比[转]
转自:http://www.zzbeidaqingniao.com/linux/20100127/1495.html linux最早由Linus Benedict Torvalds在1991年开始编写 ...
- jquery选择器之层级选择器
HTML示例代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- [转]js中的字符串函数集和代码片段
JS自带函数 concat将两个或多个字符的文本组合起来,返回一个新的字符串.var a = "hello";var b = ",world";var c = ...
- I do not want to inherit the child opacity from the parent in CSS(不想让子元素继承父元素的透明度)
Instead of using opacity, set a background-color with rgba, where 'a' is the level of transparency. ...
- mac android studio 编译时报Class JavaLaunchHelper is implemented in both
Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Cont ...
- Perl 随笔
1. .pl 文件带入参数: ./auto_cfg.pl ./mconfig.config ./boardconfig.config ./menuconfig.config .ver ./a ...
- WebApi:过滤器的种类
WebApi:筛选器的种类 授权筛选器:这些筛选器用于实现IAuthorizationFilter和做出关于是否执行操作方法(如执行身份验证或验证请求的属性)的安全决策.AuthorizeAttrib ...
- oracle数据库对象使用说明
1.创建一个分区表,并插入一些数据,同时查询出每个分区的数据. 答:创建分区表如下 2.创建一个视图,并给出一个查询语句. 3.在当前用户下创建一个同义词,用于查询scott用户下的dept表,并给出 ...
- (C# Binary Tree) 基本概念和算法
A binary tree is defined as a tree where each node can have no more than two children. Building a Bi ...