import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class Test {
public static void main(String[] args) {
String email = "****";
String password = "*****";
String point = "12";
String sessionId = "";
try {
URL url = new URL("**********");
URLConnection urlC = url.openConnection();
HttpURLConnection httpUrlConnection = (HttpURLConnection) urlC;
// 设置是否向httpUrlConnection读入
httpUrlConnection.setDoInput(true);
// 设置是否向httpUrlConnection输出
httpUrlConnection.setDoOutput(true);
// post请求时,不能使作缓存
httpUrlConnection.setUseCaches(false);
// 设定传输的内容是否是可序列化java对象
// httpUrlConnection.setRequestProperty("User-Agent",
// "Mozilla/4.0 (compatible; MSIE 8.0; Windows vista)");
httpUrlConnection.setRequestMethod("POST");
// 连接
httpUrlConnection.connect();
// String cookieVal =
// httpUrlConnection.getHeaderField("Set-Cookie");
// System.out.println(cookieVal);
// String sessionId = "";
// if(cookieVal != null){
// sessionId = cookieVal.substring(cookieVal.indexOf("=")+1,
// cookieVal.indexOf(";"));
// }
// System.out.println(sessionId);
// httpUrlConnection.setRequestProperty("Cookie", sessionId);
//httpUrlConnection.setRequestProperty("connection", "Keep-Alive");
StringBuffer sb = new StringBuffer();
//sb.append("point=" + point);
sb.append("email=" + email);
sb.append("&password=" + password);
//sb.append("&login_type=" + "1001");
// post信息
OutputStream os = httpUrlConnection.getOutputStream();
os.write(sb.toString().getBytes("utf-8"));
os.close();
BufferedReader br = new BufferedReader(new InputStreamReader(
httpUrlConnection.getInputStream()));
String str = br.readLine();
while (str != null) {
System.out.println(new String(str.getBytes(), "utf-8"));
str = br.readLine();
}
System.out.println(httpUrlConnection.getResponseCode());
System.out.println("-------------------------------------------------------");
String key = "";
if (httpUrlConnection != null) {
for (int i = 1; (key = httpUrlConnection.getHeaderFieldKey(i)) != null; i++) {
if (key.equalsIgnoreCase("set-cookie")) {
sessionId = httpUrlConnection.getHeaderField(key);
sessionId = sessionId.substring(0, sessionId.indexOf(";"));
}
}
}
httpUrlConnection.disconnect();
URL url01 = new URL("*******");
HttpURLConnection connection = (HttpURLConnection)url01.openConnection();
connection.setRequestProperty("Cookie",sessionId);
connection.setDoInput(true);
// 设置是否向httpUrlConnection输出
connection.setDoOutput(true);
// post请求时,不能使作缓存
connection.setUseCaches(false);
connection.connect();
StringBuffer sb01 = new StringBuffer();
//sb.append("point=" + point);
sb01.append("post_key=" + "aeefb46687be44ee606a58106bdbe398");
sb01.append("&mode=" + "finish");
sb01.append("&diary_title=" + "88");
sb01.append("&diary_body=" + "88");
OutputStream os01 = connection.getOutputStream();
os01.write(sb01.toString().getBytes("utf-8"));
os01.close();
BufferedReader br01 = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String str01 = br01.readLine();
while (str01 != null) {
System.out.println(new String(str01.getBytes(), "utf-8"));
str01 = br01.readLine();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
分享到:
相关推荐
代码 基于RPCA异常值检测代码代码 基于RPCA异常值检测代码代码 基于RPCA异常值检测代码代码 基于RPCA异常值检测代码代码 基于RPCA异常值检测代码代码 基于RPCA异常值检测代码代码 基于RPCA异常值检测代码代码 基于...
matlab运动目标检测代码,应用了高斯混合滤波。
XSS测试代码 安全测试 XSS测试代码大全
tensorflow-gpu测试代码
matlab边缘检测代码 特征识别 m文件 随便换张图片都能用 不能用可以给我留言
原始的SIFT特征点检测代码(http://www.cs.ubc.ca/~lowe/keypoints/)要依赖好几个库,还需要OpenCV,调用繁琐,而且速度也一般。 为了大家考虑,建议使用原始代码练习一下,但愿大家都不下载此资源;如果只想图个...
struts2学习测试代码,struts2学习测试代码2struts2学习测试代码,struts2学习测试代码
作用域测试代码
键盘测试代码就是用来模拟这个过程,检测每个按键能否正常工作。 测试代码的实现可能包括以下几个步骤: 1. **事件监听**:程序需要监听键盘事件,这通常通过注册键盘事件处理器实现。在大多数编程语言中,都有...
6. **断言**:断言是一种在开发阶段检测代码逻辑错误的有效工具。通过在关键点插入断言,当条件不满足时,程序会立即停止,帮助开发者快速定位问题。 7. **覆盖率测试**:为了确保代码的全面性,可以使用覆盖率工具...
8. **使用说明**:这是一份重要的文档,它指导用户如何安装必要的软件、设置环境变量、加载模型和运行检测代码,对于非专业背景的人来说尤其有用。 9. **道路安全**:道路坑洞检测在实际生活中有着广泛的应用,能...
struts2学习测struts2学习测试代码试代码
cplex测试代码,用于测试cplex软件在matlab中是否可以正常运行
本项目提供的测试代码旨在实现与LIS3DH加速度传感器的通信,支持两种常用接口:IIC(Inter-Integrated Circuit)和SPI(Serial Peripheral Interface)。LIS3DH是一款高性能、低功耗的三轴线性加速度计,适用于运动...
python+rabird.winio的测试代码
本篇文章将详细探讨C语言的测试代码及其重要性,以及如何进行有效的测试。 C语言是一种结构化编程语言,它的语法简洁,对硬件的控制能力强,这使得它成为编写操作系统、嵌入式系统以及各种复杂软件的首选。在开发...
可以对所生成的随机数进行游程检测,检验随机数的独立性是否符合要求。
项目提供的运行数据可能包括了训练集、验证集和测试集,这些数据集通常由大量带有标注的人脸图像组成,用于训练和评估模型的性能。在训练过程中,深度学习模型会根据这些图像学习到人脸的特征,并在新的图像上进行...
本项目实现的是32位加法器,实现思路为连接4个8位加法器,已通过vivado Simulation。 使用语言:Verilog 使用软件:vivado 本项目包含: 1、vivado项目文件adder_32....3、vivado自动生成的文档(含设计代码和测试代码)
这个名为“锂电池检测代码.rar”的压缩包文件显然包含了实现锂电池状态检测的软件代码。下面将详细探讨其中涉及的知识点: 1. 图像处理:描述中提到的“图像裁剪”和“归一化”是计算机视觉领域的基本操作。图像...