Java中伪造referer来获取数据
生活随笔
收集整理的這篇文章主要介紹了
Java中伪造referer来获取数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
偽造方法,參考代碼:
public class HelloA {private String large = new String(new char[100000]); public String getSubString() { return this.large.substring(0,2); } @Testpublic void test(){InputStream in = responseInputStream();try {if(in != null){FileOutputStream out = new FileOutputStream("C:\\Users\\User\\Desktop\\test.zip");writeInTxt(in,out);}} catch (FileNotFoundException e) {e.printStackTrace();} }public void writeInTxt(InputStream in, FileOutputStream out) {//char[] bytes = new char[1024];byte[] bytes = new byte[1024];int len = 0;try {//InputStreamReader isr = new InputStreamReader(in,"UTF-8");//OutputStreamWriter osw = new OutputStreamWriter(out,"UTF-8");while((len = in.read(bytes)) !=-1){out.write(bytes, 0, len);}} catch (IOException e) {e.printStackTrace();}}public InputStream responseInputStream(){InputStream in = null;/*String cookie="BAIDUID=4AB62207ED7EE9F7D5639F99FD2C93FB:FG=1; PSTM=1460857252; "+"BIDUPSID=187A5BC1E5DD0DEF05E21F73A29835EF; _5t_trace_sid=1ea40703c286c635041c90d9a5f70580; "+"_5t_trace_tms=1; H_PS_645EC=5b3dg%2Bo1fZjiciiEjCjOit34qHNoqmVzbHSdPYr%2FQo9iGTj%2BpjOjY0%2FE7%2Bo; "+"BD_CK_SAM=1; BD_HOME=0; H_PS_PSSID=19638_19289_1439_19713_19806_19559_19808_19843_19902_17001_15557_11849; BD_UPN=12314353";*/try {HttpURLConnection conn = (HttpURLConnection) new URL("http://www.baidu.com/").openConnection();conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36)");conn.setRequestProperty("Accept-Encoding", "gzip, deflate, sdch");conn.setRequestProperty("referer", "http://www.baidu.com/");//conn.setRequestProperty("Cookie", cookie);conn.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8");conn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");conn.setRequestMethod("GET");conn.setDoInput(true);int respcode=conn.getResponseCode();if(respcode == 200)in = conn.getInputStream();} catch (MalformedURLException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return in;} }????通過上述代碼就可以實現與HttpClient工具相似的功能,偽造referer來發送請求,獲取響應,這里要注意的是返回的數據是zip格式的?;蛘咧苯訉慍:\\Users\\User\\Desktop\\test,test后面不帶zip等任何后綴,最后也能得到自己想要的響應的數據。
????因此,分步走的頁面,比如員工注冊,分為三步走,第一步:校驗識別號和用戶名,校驗完成以后調到第二個頁面,校驗手機號,手機號校驗完成后,跳到第三個頁面輸入會員名的頁面完成注冊。為防止模擬器模擬參數請求,直接進到第二個頁面,那么可以在后臺處理方法里面使用map來存儲,用戶名作為key,1或2作為value,再寫一個攔截第二個和第三個頁面的過濾器。在doFilter方法里面,根據這個map的value值來判斷是不是第一個頁面轉過來的。
轉載于:https://my.oschina.net/wliming/blog/673401
總結
以上是生活随笔為你收集整理的Java中伪造referer来获取数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: APK签名校验绕过
- 下一篇: PHP变量的变量——可变变量