题目:在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. Java中 Collection 、 List 、 Set 、 Map详解

    一.容器( Collection ) 接口    容器( Collection )是最基本的集合接口,一个容器( Collection )保存一组对象( Object ),即对象是容器的元素( Ele ...

  2. css未知宽度水平居中整理

    1.text-align 兼容性很好 .wp {text-align: center;} .test {display: inline;} <ul class="wp"> ...

  3. gdb手册

    摘自:https://github.com/hellogcc/100-gdb-tips/blob/master/src/quit-gdb-silently.md. 我只是摘抄我平时没注意到的,或者我认 ...

  4. 需求管理是CMM可重复级中的6个关键过程域之一,其主要目标是__________。A.客观地验证需求管理活动

    需求管理是CMM可重复级中的6个关键过程域之一,其主要目标是__________.A.客观地验证需求管理活动       需求管理是CMM可重复级中的6个关键过程域之一,其主要目标是_________ ...

  5. JVM垃圾回收机制二

    对象的回收 垃圾的回收涉及的几个问题:何时回收,由谁回收,怎样回收.这几个问题我们一一来解决. 1.何时回收----对象的生死判定 对象达到什么条件才能判断这个对象已经无用了.常见的判断对象生死的方法 ...

  6. 一张图告诉你,只会这些HTML还远远不够!!!!!

    不知道自己HTML水平如何,不知道HTML5如何进化?看这张图 如果一半以上的你都不会,必须看这本书,阿里一线工程师用代码和功能页面来告诉你每一个技术点. 都会一点,但不知道如何检验自己,看看本书提供 ...

  7. JS中的回收机制

    js的设计者为了让没有必要的变量保存在内存中,(我们写的任何变量都是需要内存空间的),什么叫没有必要的变量?也就是说你不在需要这个变量的时候它就会被销毁?那么你肯定会问js怎么知道那些变量是我们不需要 ...

  8. 【学习笔记】CSS优先级规则

    CSS的优先级规则很多地方的说法都是错误的,常见错误说法是inline css>内部样式>外部样式,其实并没有这种规定.真正的CSS优先级确定是通过特性值大小确定的,在特性值大小相同的情况 ...

  9. Idea注释参数报错,控制台乱码问题解决方法

    idea虽然工具非常好用,但是他的一些解决方法网上非常的少,有些压根没有,解决这些问题非常浪费时间 1.最近在工作中发现一个问题,使用ant打包后,控制台总是报错,提示信息还是乱码的,吓得我赶紧用回了 ...

  10. HDU 1398 Square Coins 平方硬币 (普通母函数,水)

    题意: 有17种硬币,每种的面值为编号的平方,比如 1,4,9,16.....给出一个数字,求组成这个面值有多少种组法? 思路: 用普通母函数解,主要做的就是模拟乘法,因为硬币是无限的,所以每个构造式 ...