千里码4:GET&POST
来源:互联网 发布:帝国cms小说 编辑:程序博客网 时间:2024/06/05 12:06
这题的答案是:
restful
,但是只接受POST请求的提交哦。
答题框下面的提交按钮是按GET方式提交,服务器却只接受POST方式提交的答案,(真是磨人的小妖精)。所以要自己用各种POST方式提交答案。
问题是不能只是把答案简单的用POST方式提交到接受答案的URL,还要告诉URL你是谁,不然答了也是白答,所以要用到cookies。
先用chrome或其他浏览器的开发者工具抓包,查询到接受答案的URL,还有各种HTTP协议文件项,cookies,token,这些东西,然后先点代码发到接受答案的URL,当然要按POST方式的格式。
下面的代码引用自该task的学习资料
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import java.net.URL;import java.net.URLConnection;public class test{ public static void main(String[] args) throws IOException { String urlStr = "http://www.qlcoder.com/task/4/solve"; URL url = new URL(urlStr); URLConnection conn = url.openConnection(); conn.setRequestProperty("Accept", "application/json, text/javascript, */*; q=0.01"); conn.setRequestProperty("Accept-Encoding", "gzip, deflate, sdch"); conn.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8"); conn.setRequestProperty("Connection", "keep-alive"); conn.setRequestProperty("Cookie", "**your cookie here**"); conn.setDoOutput(true); conn.setDoInput(true); PrintWriter pw = new PrintWriter(conn.getOutputStream()); pw.print("answer=restful&_token=**your token here**"); pw.flush(); BufferedReader reader = new BufferedReader( new InputStreamReader(conn.getInputStream())); String line = null; while((line = reader.readLine()) != null) { System.out.println(line); } reader.close(); }}
0 0
- 千里码4:GET&POST
- 【千里码】Task4-Get&Post
- 4GET&POST
- 关于"Get&Post"——千里码(4)
- post get
- Get, Post
- GET/POST
- get/post
- get post
- get post
- get post
- post get
- post get
- Get && Post
- get & post
- get & post
- get/post
- post & get
- 字符串按单词逆序输出
- Android之机型适配
- 指令周期的数据流
- 前端开发框架对比
- Linux常用命令-------其它
- 千里码4:GET&POST
- 35. 内容协商和转码
- 面向对象_final修饰变量的初始化时机
- Struts2学习——0100HelloStruts
- 基础算法模块总结
- LeetCode------------single-number-ii
- noip2013积木大赛
- Oracle 的过程和函数
- hdu3526(最小费用流)