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异常值检测代码代码 基于...
串口测试代码串口测试代码串口测试代码串口测试代码
tensorflow-gpu测试代码,测试成功会输出GPU True
matlab运动目标检测代码,应用了高斯混合滤波。
spp-c蓝牙练习程序。练习蓝牙通信的代码
XSS测试代码 安全测试 XSS测试代码大全
tensorflow-gpu测试代码
压力测试代码压力测试代码压力测试代码压力测试代码压力测试代码压力测试代码压力测试代码压力测试代码压力测试代码压力测试代码压力测试代码压力测试代码压力测试代码压力测试代码压力测试代码压力测试代码压力测试...
matlab边缘检测代码 特征识别 m文件 随便换张图片都能用 不能用可以给我留言
原始的SIFT特征点检测代码(http://www.cs.ubc.ca/~lowe/keypoints/)要依赖好几个库,还需要OpenCV,调用繁琐,而且速度也一般。 为了大家考虑,建议使用原始代码练习一下,但愿大家都不下载此资源;如果只想图个...
自己编写的测试代码
struts2学习测试代码,struts2学习测试代码2struts2学习测试代码,struts2学习测试代码
https://blog.csdn.net/m0_56289903/article/details/121286804?spm=1001.2014.3001.5501 的IO测试代码
android4.0测试代码;android4.0测试代码;android4.0测试代码;android4.0测试代码
MQ-2气体传感器: 应用:适用于家庭或工厂的...3、代码使用KEIL 开发,当前在STM32F103C8T6运行,如果是STM32F103其他型号芯片,依然适用,请自行更改KEIL芯片型号以及FLASH容量即可。 4、技术服务:349014857@qq.com
hibernate入门代码,附有测试代码
作用域测试代码
ruby测试代码6
SSH架构测试代码,很好的测试代码,最新整理的,用于学习
工厂模式的测试代码!工厂模式的测试代码