Java登陆测试
package test001; import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL; import org.apache.commons.io.IOUtils; public class testhttpx {
public static void testPost01() throws IOException {
String surl = "http://login.goodjobs.cn/index.php/action/UserLogin";
/**
* 首先要和URL下的URLConnection对话。 URLConnection可以很容易的从URL得到。比如: // Using
* java.net.URL and //java.net.URLConnection
*/
URL url = new URL(surl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); /**
* 然后把连接设为输出模式。URLConnection通常作为输入来使用,比如下载一个Web页。
* 通过把URLConnection设为输出,你可以把数据向你个Web页传送。下面是如何做:
*/
connection.setDoOutput(true);
/**
* 最后,为了得到OutputStream,简单起见,把它约束在Writer并且放入POST信息中,例如: ...
*/
OutputStreamWriter out = new OutputStreamWriter(connection
.getOutputStream(), "GBK");
//其中的memberName和password也是阅读html代码得知的,即为表单中对应的参数名称
out.write("memberName=myMemberName&password=myPassword"); // post的关键所在!
// remember to clean up
out.flush();
out.close(); // 取得cookie,相当于记录了身份,供下次访问时使用
String cookieVal = connection.getHeaderField("Set-Cookie");
String s = "http://user.goodjobs.cn/dispatcher.php/module/Resume/action/Preview";
//重新打开一个连接
url = new URL(s);
HttpURLConnection resumeConnection = (HttpURLConnection) url
.openConnection();
if (cookieVal != null) {
//发送cookie信息上去,以表明自己的身份,否则会被认为没有权限
resumeConnection.setRequestProperty("Cookie", cookieVal);
}
resumeConnection.connect();
InputStream urlStream = resumeConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(urlStream));
String ss = null;
String total = "";
while ((ss = bufferedReader.readLine()) != null) {
total += ss;
}
IOUtils.write(total, new FileOutputStream("d:/index.html"));
bufferedReader.close();
} public static void main(String[] args) throws IOException { testPost01(); }
}
package test001; import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL; import org.apache.commons.io.IOUtils; public class testhttps {
public static void testPost02() throws IOException {
String surl = "http://www.dekevin.com/wp-login.php";
/**
* 首先要和URL下的URLConnection对话。 URLConnection可以很容易的从URL得到。比如: // Using
* java.net.URL and //java.net.URLConnection
*/
URL url = new URL(surl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); /**
* 然后把连接设为输出模式。URLConnection通常作为输入来使用,比如下载一个Web页。
* 通过把URLConnection设为输出,你可以把数据向你个Web页传送。下面是如何做:
*/
connection.setDoOutput(true);
/**
* 最后,为了得到OutputStream,简单起见,把它约束在Writer并且放入POST信息中,例如: ...
*/
OutputStreamWriter out = new OutputStreamWriter(connection
.getOutputStream(), "GBK");
//其中的memberName和password也是阅读html代码得知的,即为表单中对应的参数名称
out.write("log=dekevin&pwd=luowende103807"); // post的关键所在!
// remember to clean up
out.flush();
out.close(); // 取得cookie,相当于记录了身份,供下次访问时使用
String cookieVal = connection.getHeaderField("Set-Cookie");
String s = "http://www.dekevin.com/wp-admin/";
//重新打开一个连接
url = new URL(s);
HttpURLConnection resumeConnection = (HttpURLConnection) url
.openConnection();
if (cookieVal != null) {
//发送cookie信息上去,以表明自己的身份,否则会被认为没有权限
resumeConnection.setRequestProperty("Cookie", cookieVal);
}
resumeConnection.connect();
InputStream urlStream = resumeConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(urlStream));
String ss = null;
String total = "";
while ((ss = bufferedReader.readLine()) != null) {
total += ss;
}
IOUtils.write(total, new FileOutputStream("d:/index.html"));
bufferedReader.close();
} public static void main(String[] args) throws IOException { testPost02(); } }
Java登陆测试的更多相关文章
- LoadRunner调用java函数测试oracle
LoadRunner调用java函数测试oracle 测试oracle的方法有很多,可以使用loadrunner的oracle协议直接调用oracle进行测试,也可以调用开发的java程序对oracl ...
- Java反序列化测试
前言:有没有想过,如何将对象进行“加密”后写入磁盘?序列化帮你实现! 1.概念 序列化 (Serialization)将对象的状态信息转换为可以存储或传输的形式的过程.在序列化期间,对象将其当前状态写 ...
- 零成本实现接口自动化测试 – Java+TestNG 测试Restful service
接口自动化测试 – Java+TestNG 测试 Restful Web Service 关键词:基于Rest的Web服务,接口自动化测试,数据驱动测试,测试Restful Web Service, ...
- Android AIDL自动生成Java文件测试
/******************************************************************************** * Android AIDL自动生成 ...
- Java阶段性测试--知识点:数组,面向对象,集合、线程,IO流
#Java基础测试 涉及知识点:数组,面向对象,重载,重写,继承,集合,排序,线程,文件流 一.多项选择题(可能是单选,也可能是多选) 1.下列标识符命名不合法的是( D ). A.$_Name ...
- JMeter 压测基础(四)——Java工程测试
JMeter Java工程测试 1.eclipse中新建工程 2.导入需要的jar包 从JMeter安装目录lib/ext中两个jar包buildPath到Java project中,分别是“Apac ...
- Java常用测试工具
第一部分:九款性能测试 Java入门 如果你才刚开始接触Java世界,那么要做的第一件事情是,安装JDK——Java Development Kit(Java开发工具包),它自带有Java Runti ...
- 第一次java程序测试感受
第一次JAVA程序设计测试,检验了一个暑假的成果.显而易见,我做的并不是很好,程序最起码的输入输出以及方法的定义还是没有问题的,但是考到了文件输入输出便看出来了.对于文件的输入输出,虽然我预习到那里, ...
- 接口自动化测试框架搭建 – Java+TestNG 测试Restful service
接口自动化测试 – Java+TestNG 测试 Restful Web Service 关键词:基于Rest的Web服务,接口自动化测试,数据驱动测试,测试Restful Web Service, ...
随机推荐
- git删除中文文件
git中出现如下代码时,是因为文件中包含中文.而且我们也无法用 git rm name 命令来删除该文件. deleted: "chrome_plugin/source_file/iHub\ ...
- ngui 脚本绘制sprite
public GameObject _background; public UIAtlas atlas; private Dictionary<int, UISprite> _allCar ...
- get mac 20150202
getmac.sh #!/bin/sh cat oui.txt|sed -e :a -e '$!N;s/\n\s/=/;ta' -e 'P;D' | sed 's/(hex)\+/=/g' | sed ...
- mysql 幻读
幻读(Phantom Read) 是指当用户读取某一范围的数据行时,B事务在该范围内插入了新行,当用户再读取该范围的数据行时,会发现有新的“幻影”行.InnoDB和Falcon存储引擎通 过多版本并发 ...
- Flash挡住DIV的解决方法
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://down ...
- UPC 2224 Boring Counting ★(山东省第四届ACM程序设计竞赛 tag:线段树)
[题意]给定一个长度为N的数列,M个询问区间[L,R]内大于等于A小于等于B的数的个数. [题目链接]http://acm.upc.edu.cn/problem.php?id=2224 省赛的时候脑抽 ...
- 【 D3.js 高级系列 — 1.0 】 文本的换行
在 SVG 中添加文本是使用 text 元素.但是,这个元素不能够自动换行,超出的部分就显示不出来了,怎么办呢? 高级系列开篇前言 从今天开始写高级系列教程.还是那句话,由于本人实力有限,不一定保证入 ...
- JDK7新特性之fork/join框架
The fork/join framework is an implementation of the ExecutorService interface that helps you take ad ...
- 重温delphi之:如何将Bitmap位图与base64字符串相互转换
先引用delphi自带的单元 uses EncdDecd; 然后就可以使用下面二个函数了: by 菩提树下的杨过 http://yjmyzz.cnblogs.com/ ///将Bitmap位图转化为b ...
- 【HTML】Advanced7:HTML5 Forms Pt. 2: Attributes and Data Lists
1.<label for"" ></label> <input type="email" placeholder=" & ...