题目:在A页面登录后,重定向到A页面,然后访问B页面,header中带一指定内容"Content":"2018",然后从response中读取answer的值。

主要分三步分,首先在A页面发送POST请求:

String url = "http://192.168.1.105/";
String responseMsg = "";
byte[] responseBody = null;
HttpClient httpclient = new HttpClient();
httpclient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
httpclient.getParams().setParameter("http.protocol.single-cookie-header", true);
PostMethod httpPost = new PostMethod(url);
httpPost.setRequestHeader("ContentType", "application/xml;charset=utf-8");
String cookie = ".AspNetCore.Antiforgery.2asieuWmzUU=CfDJ8LzDUhYKe7pEsWY4r-H8oTev6zo3ttt4qg9Zo6xNEWNET1tpSwNSHS9SQf2xe1p9witfHgmLnLx1HKCvGsynU6Sv-YMB4u_Pbh0ZAQRoEAJ7KVGH09LsqrBowNV1uh6iU71ealeplU4Yps3td_dBh0I";
httpPost.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
httpPost.setRequestHeader("Accept-Encoding", "gzip, deflate");
httpPost.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.9");
httpPost.setRequestHeader("Cache-Control", "max-age=0");
httpPost.setRequestHeader("Connection","Keep-Alive");
httpPost.setRequestHeader("Content-Length", "274");
httpPost.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setRequestHeader("Host", "192.168.1.105");
httpPost.setRequestHeader("Origin", "192.168.1.105");
httpPost.setRequestHeader("Origin", "http://192.168.1.105");
httpPost.setRequestHeader("Referer", "http://192.168.1.105/");
httpPost.setRequestHeader("Upgrade-Insecure-Requests", "1");
httpPost.setRequestHeader("User-Agent", Constants.USER_AGENT);
httpPost.setRequestHeader("Cookie", cookie);//ltpatoken+sessionid
httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(6000000);
httpclient.getHttpConnectionManager().getParams().setSoTimeout(6000000);
try {
httpPost.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new DefaultHttpMethodRetryHandler(3, false));
NameValuePair certsn=new NameValuePair("Input.Email", "yxteng@126.com");
NameValuePair certinfo=new NameValuePair("Input.Password", "&wxZC3`jBqo)'qtX");
NameValuePair subdn=new NameValuePair("__RequestVerificationToken", "CfDJ8LzDUhYKe7pEsWY4r-H8oTdN9wZgh60Tje5CyRR89Ps2Y67XUzTS7MdnpqmYWOjxqHVytkJq_cV3z8vwvsK6729LWWH1MRlV1QF6tqWRiOGEphxLKkbUxoKQfVEVRRjXV5LTKZafolsgJyOp0YbKnow");
NameValuePair ramcode=new NameValuePair("Input.RememberMe", "false");
httpPost.setRequestBody(new NameValuePair[]{certsn,certinfo,subdn,ramcode});
LogUtils.info("开始登陆...");
int statusCode = httpclient.executeMethod(httpPost);
Cookie[] cookies = httpclient.getState().getCookies();
cookie="";
for (int i = 0; i < cookies.length; i++) {
cookie+=cookies[i].toString();
if(i!=cookies.length-1){
cookie+=";";
}
LogUtils.info(cookies[i].getName()+":"+cookies[i].getValue());
}
LogUtils.info("COOKIE:"+cookie);
if (statusCode == HttpStatus.SC_OK) {
responseBody = httpPost.getResponseBody();
LogUtils.info("登陆成功"+statusCode);
}
else {
responseMsg = String.valueOf("statusCode:"+statusCode);
LogUtils.error("登陆失败"+statusCode);
}

  然后get方法模拟重定向到本页:

cookie = ".AspNetCore.Antiforgery.2asieuWmzUU=CfDJ8LzDUhYKe7pEsWY4r-H8oTev6zo3ttt4qg9Zo6xNEWNET1tpSwNSHS9SQf2xe1p9witfHgmLnLx1HKCvGsynU6Sv-YMB4u_Pbh0ZAQRoEAJ7KVGH09LsqrBowNV1uh6iU71ealeplU4Yps3td_dBh0I; .AspNetCore.Identity.Application=CfDJ8LzDUhYKe7pEsWY4r-H8oTfyoqahKhxlTHouYjwJDlVmJ6BdZ8pxXvOLoHDu_Ci9kzyy9GKtpRYYF06bLr3flLY6oiM7ZEJRAH-ARkiwchgjVNWPB2STXkc42E-NtLz94J9RVVhluNbN99JUUCdSXKqQgj0MUq4EpB6D4zF-Diu2wkWjhIty8HxLX4-JG6r3X8XvcJnDyqwt4YgWimcJ_SrIsfS4xdem-9zBK4zPJtorPZZwlOah0IYR7hLd7-2TaJxCk_QvQG5GIaAqRc4A-2I8eR5g6irx9SgI0XIBdxEuqpqUn1er5CIf0olBK3VXtzwNEwDTv8AkDqDvOxw7m9kjkEgDrYs3LmgDpjsg5bgiSrCcfoFx_X_ODp7Q-g5dZLOqYZQxD-bMRy3Uwu97JX-nLqtMLKoY0POhSYX17Y_SH4vFgu9e3I8matifsZAuzKIaT4DFrzyhf_ihi1ffxLnIhYnydMuM27RgrMDNq1EUue1Edym4XUhgxJjKOoiMLg_paJ14l85OXu_M51upCNB4568YKARPVJiT0SCFaA61rYoVOpZaexNLQbxc6kxe0jB5BthCVjU00xpt96QeZPU";
LogUtils.info("开始跳转首页...");
url = "http://192.168.1.105/";
GetMethod httpget = new GetMethod(url);
httpget.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
httpget.setRequestHeader("Accept-Encoding", "gzip, deflate");
httpget.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.9");
httpget.setRequestHeader("Cache-Control", "max-age=0");
httpget.setRequestHeader("Connection","Keep-Alive");
httpget.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpget.setRequestHeader("Host", "192.168.1.105");
httpget.setRequestHeader("Referer", "http://192.168.1.105/");
httpget.setRequestHeader("Upgrade-Insecure-Requests", "1");
httpget.setRequestHeader("User-Agent", Constants.USER_AGENT);
httpget.setRequestHeader("Cookie", cookie);//ltpatoken+sessionid
statusCode = httpclient.executeMethod(httpget);
if (statusCode == HttpStatus.SC_OK) {
responseBody = httpget.getResponseBody();
LogUtils.info("跳转V成功"+statusCode);
}
else {
responseMsg = String.valueOf("statusCode:"+statusCode);
LogUtils.error("跳转V失败"+statusCode);
return;
}

  最后访问目标页,header中带上指定内容:

url = "http://192.168.1.105/Problems/HttpRequest";
httpget = new GetMethod(url);
httpget.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
httpget.setRequestHeader("Accept-Encoding", "gzip, deflate");
httpget.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.9");
httpget.setRequestHeader("Cache-Control", "max-age=0");
httpget.setRequestHeader("Connection","Keep-Alive");
httpget.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpget.setRequestHeader("Host", "192.168.1.105");
httpget.setRequestHeader("Referer", "http://192.168.1.105/");
httpget.setRequestHeader("Upgrade-Insecure-Requests", "1");
httpget.setRequestHeader("Content", "2018");//秘钥
httpget.setRequestHeader("User-Agent", Constants.USER_AGENT);
httpget.setRequestHeader("Cookie", cookie);//ltpatoken+sessionid
statusCode = httpclient.executeMethod(httpget);
if (statusCode == HttpStatus.SC_OK) {
Header[] hlist= httpget.getResponseHeaders();
for(Header h:hlist){
LogUtils.info(h.getName()+":"+h.getValue());
}
LogUtils.info("跳转V成功"+statusCode+responseBody);
}
else {
responseMsg = String.valueOf("statusCode:"+statusCode);
LogUtils.error("跳转V失败"+statusCode+responseBody);
return;
}

  在控制台中查看答案即可。

某比赛小记2- 从HTTP请求返回中获得答案的更多相关文章

  1. nodejs中使用http请求返回值为html时乱码问题

    今天用nodejs进行http请求时返回的数据是一个html文件,然后我还是按照以前解析json数据的方法.果不其然报错了:SyntaxError: Unexpected token  in JSON ...

  2. ionic 发送请求返回一直都是404

    在web端调试一直都没有问题,生成app之后发现所有的请求返回的都是404, 断掉wifi和4G之后发送的也是404 原因是未引入插件 解决方法是在根目录下执行一下命令 cordova plugin ...

  3. http请求返回响应码的意思

    HTTP 状态响应码 意思详解/大全 HTTP状态码(HTTP Status Code)是用以表示网页服务器HTTP响应状态的3位数字代码.它由 RFC 2616 规范定义的,并得到RFC 2518. ...

  4. HTTP请求返回状态详解

    当用户试图通过 HTTP 访问一台正在运行 Internet 信息服务 (IIS) 的服务器上的内容时,IIS 返回一个表示该请求的状态的数字代码.状态代码可以指明具体请求是否已成功,还可以揭示请求失 ...

  5. js:如何在循环异步请求的每次返回中添加想要的值

    先看一个场景 var arr = ["a","b","c"]; for (var i in arr) {         $.get(&qu ...

  6. ajax请求返回数据,模板中的数据处理

    /*ajax请求返回数据,模板中的数据处理*/ function QueryGameAsset(){ var new_start_time=$('#new_start_time').val();//开 ...

  7. postman简单教程,如何在请求中引用上次请求返回的值

    做接口测试,一定会遇到这种情况,需要拿上次请求的值在本次请求中使用,比如,我们去测试一个东西,要去登录才能做其他的操作,需要拿到登录返回数据中的某些字段,比如,token啊等... 如果发一次请求,就 ...

  8. 如何解决http请求返回结果中文乱码

    如何解决http请求返回结果中文乱码 1.问题描述 http请求中,请求的结果集中包含中文,最终以乱码展示. 2.问题的本质 乱码的本质是服务端返回的字符集编码与客户端的编码方式不一致. 场景的如服务 ...

  9. http请求返回响应码及意义

    http 响应码及意义 HTTP状态码(HTTP Status Code)是用以表示网页服务器HTTP响应状态的3位数字代码.它由 RFC 2616 规范定义的,并得到RFC 2518.RFC 281 ...

随机推荐

  1. Codeforces Round #533(Div. 2) D.Kilani and the Game

    链接:https://codeforces.com/contest/1105/problem/D 题意: 给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...

  2. #13:人十我一Orz——6

    水题放送,写得依旧丑: #include <cstdio> #include <cstring> #include <cmath> #include <alg ...

  3. 24 使用Maven 或 Gradle构建groovy

    1       使用Maven 或 Gradle构建groovy 1.1  使用maven构建groovy pom.xml file. <dependencies>     ... oth ...

  4. Unity Shader入门精要学习笔记 - 第9章 更复杂的光照

    转载自 冯乐乐的<Unity Shader入门精要> Unity 的渲染路径 在Unity里,渲染路径决定了光照是如何应该到Unity Shader 中的.因此,如果要和光源打交道,我们需 ...

  5. game 竞赛图 缩环

    [问题背景] zhx 和他的妹子(们)做游戏. [问题描述] 考虑 N 个人玩一个游戏, 任意两个人之间进行一场游戏 (共 N*(N-)/ 场) , 且每场一定能分出胜负. 现在,你需要在其中找到三个 ...

  6. 从零开始利用vue-cli搭建简单音乐网站(八)

    这是完成了预想中的最后两个功能:歌曲评论以及歌曲搜索. 1.评论效果: 用户点击评论按钮,评论框获取焦点. 输入之后点击提交,下方显示评论,用户名称以及日期.相应的用户也可以删除自己评论. 当然只能删 ...

  7. uvm_reg——寄存器模型(三)

    uvm_reg 是uvm_reg_field , 包含所有uvm_reg_field 所有的函数.

  8. Java MVC 分页实例

    共4个文件 requestLogList.jsp RequestInfoController.java RequestInfoBean.java RequestInfoService.java 1.r ...

  9. Jenkins结合ant传递参数

    需求: 使用Jenkins的「参数化构建过程」,由用户手动输入参数.通过ant脚本接收这个参数,并输出(当然,中间也可以进行复杂的处理,这里为了说明问题,仅做简单的输出). 1.基础环境 Jenkin ...

  10. myeclipse报错MA

    以下问题萌新问了我很多次了,无奈写个随笔.之后问的我都在这个随笔里补充. 断电/自动关机导致的问题: Could not open the editor: the file does not exis ...