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登陆测试的更多相关文章

  1. LoadRunner调用java函数测试oracle

    LoadRunner调用java函数测试oracle 测试oracle的方法有很多,可以使用loadrunner的oracle协议直接调用oracle进行测试,也可以调用开发的java程序对oracl ...

  2. Java反序列化测试

    前言:有没有想过,如何将对象进行“加密”后写入磁盘?序列化帮你实现! 1.概念 序列化 (Serialization)将对象的状态信息转换为可以存储或传输的形式的过程.在序列化期间,对象将其当前状态写 ...

  3. 零成本实现接口自动化测试 – Java+TestNG 测试Restful service

    接口自动化测试 – Java+TestNG 测试 Restful Web Service 关键词:基于Rest的Web服务,接口自动化测试,数据驱动测试,测试Restful Web Service, ...

  4. Android AIDL自动生成Java文件测试

    /******************************************************************************** * Android AIDL自动生成 ...

  5. Java阶段性测试--知识点:数组,面向对象,集合、线程,IO流

    #Java基础测试 涉及知识点:数组,面向对象,重载,重写,继承,集合,排序,线程,文件流 一.多项选择题(可能是单选,也可能是多选) 1.下列标识符命名不合法的是(   D  ). A.$_Name ...

  6. JMeter 压测基础(四)——Java工程测试

    JMeter Java工程测试 1.eclipse中新建工程 2.导入需要的jar包 从JMeter安装目录lib/ext中两个jar包buildPath到Java project中,分别是“Apac ...

  7. Java常用测试工具

    第一部分:九款性能测试 Java入门 如果你才刚开始接触Java世界,那么要做的第一件事情是,安装JDK——Java Development Kit(Java开发工具包),它自带有Java Runti ...

  8. 第一次java程序测试感受

    第一次JAVA程序设计测试,检验了一个暑假的成果.显而易见,我做的并不是很好,程序最起码的输入输出以及方法的定义还是没有问题的,但是考到了文件输入输出便看出来了.对于文件的输入输出,虽然我预习到那里, ...

  9. 接口自动化测试框架搭建 – Java+TestNG 测试Restful service

    接口自动化测试 – Java+TestNG 测试 Restful Web Service 关键词:基于Rest的Web服务,接口自动化测试,数据驱动测试,测试Restful Web Service, ...

随机推荐

  1. 【ZOJ】2112 Dynamic Rankings

    树状数组套主席树模板题目. /* 2112 */ #include <iostream> #include <sstream> #include <string> ...

  2. JADE平台入门

    相关介绍: JADE(Java Agent Development Framework,Java智能体开发框架) 用途: Java智能体开发框架 开发者: TILAB 主要功能: AMS.DF.ACC ...

  3. 基于Struts2的用户登录程序

    基本步骤: 1.新建Java工程,File>New>Project>Web>Dynamic Web Project,并将工程命名为:Struts2_Demo 2.导入strut ...

  4. Java [Leetcode 273]Delete Node in a Linked List

    题目描述: Write a function to delete a node (except the tail) in a singly linked list, given only access ...

  5. postgresql 行转列,拼接字符串

    create table k_user ( op_id ) not null, op_name ) not null, password ) not null, real_name ) not nul ...

  6. 【Java基础之容器】Iterator

    Iterator: ->所有实现了Collection接口的容器类都有一个iterator方法用以返回一个实现了Iterator接口的对象 ->Iterator对象称作迭代器,用以方便的实 ...

  7. (二)学习C#之内存管理

    一.当你运行你的程序通常都会访问哪些内存空间呢? 电脑自言自语道,“这个人要声明一个整数”或“这个人个方法”或“这个人要创建一个对象” 1.这些信息究竟是存在内存里的什么地方呢? 2.或者说用于描述这 ...

  8. JMX-JAVA进程监控利器

    Java 管理扩展(Java Management Extension,JMX)是从jdk1.4开始的,但从1.5时才加到jdk里面,并把API放到java.lang.management包里面. 如 ...

  9. Java序列化 如何把多个对象存储在一个文件中

    /** * 用于保存模板文件,内容包括: * 1,标志位,1 int * 2,版本   1 int * 3,数据头长度 1 int * 4,预留数据头空间  5120 byte * 5,后续数据长度  ...

  10. [原创]使用命令行工具提升cocos2d-x开发效率(二)之CocosBuilder篇

    如果你正在使用CocosBuilder或者是其他基于CocosBuilder源码改装而成的工具为你的游戏搭建场景或者UI,那你一定要看看这篇文章:)   你是否已经厌倦了无聊的手工publish操作? ...