- 浏览: 379940 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (107)
- Linux (2)
- WebService (4)
- Java基础 (18)
- 优秀博客文章 (6)
- 面试 (2)
- 视频 (1)
- 开源软件 (7)
- DOS命令、批处理 (2)
- SSH Mybatis (11)
- MQ (3)
- 个人开发者 (1)
- 设计模式 (2)
- 博客 (1)
- 缓存 (1)
- 数据库 (10)
- 工具软件 (9)
- Tomcat (3)
- 网络 (2)
- XML 、JSON (1)
- OSGI (1)
- 算法 (1)
- 计算机基础、网络 (1)
- Web 开发 (3)
- 程序人生 (1)
- Servlet基础 (1)
- 英语 (1)
- 临时、未分类 (4)
- 网路、word使用技巧 (2)
- Java性能优化 (0)
最新评论
-
360pluse:
使用apache ActiveMQ深入企业级程序设计网盘地址: ...
Active MQ技术文章(JMS) -
星辰海:
问下,像TimerTask一旦抛异常,就永远不执行了,这种情况 ...
spring学习系列 -- 定时器三 两种定时器的比较 -
360pluse:
使用apache ActiveMQ深入企业级程序设计百度网盘: ...
Active MQ技术文章(JMS) -
xj56ai:
能不能 提供一下 包
Spring 学习系列 -- Spring + Mybatis 从零开始配置多数据源访问 -
wejack639:
写的很好,很有用,谢谢
spring学习系列 -- 定时器三 两种定时器的比较
代码备用:
由chrome浏览器的开发人员工具获取请求的sCookies,模拟将军的一系列操作
加密类:
依赖库:commons-codec-1.6.jar
package com.hry.base64; import java.io.UnsupportedEncodingException; public class SendRequest2 { public static void main(String[] args) throws Exception{ String t = "3acdf44c-0a4d-4ef4-99b9-1f0d170f7117".substring(0,8); // String s = "n52Jks/b7vqWWjD0+EL/j8X8UqV8+Y+tybEmvlGO"; // String s = "nJ+OyoCPvr6ADXf1+Bn31Jqq"; // String s = "lZmImK2GtLvSUie0pRT2uJuhDo8+gNzijL965BClLCsFELaJaRij8mkaSf8vjO3BUC3Fj345b1DyG6kULnY9k1WEkUMcpv5XYp7Zpd0uwo1wfwcCqTFA6Ydx2yFdC4NfiUhbFNkMv2mViuv3qFM3XkyiS3Vzbps9m7zrI5ZfbzYpoy9lKUmJHClOJtByDqzmTWj2Bz57bpg1nZpVL72SHubBj4haK6KeEd0fJHpuscjL0grt6bgpN1ay0bBSz1JO0UxWx15a8Xh7MrpdqIgZ1wYiEWCi70J+kTzm545KMajrEioNa5hJ9/aSURCyj3IuUaw2h/66cdgbclr9Kui5l6YCkcCCr2LeERxGpy6qsQiLUrs="; // String s = ""; String s = "lZmImK2GtLvSUie0pRT2uJuhDo8+gNjijL965BClLCsFELaJZBij8mkaSf8vjO3BUC3Fg345b1DyG6kULnY9k1WFkUMcpv5XYp7Zpd0uwopwbgUC4DVG89shlmZOHspKmE5UKN5DrnzbtI31sT8yS1vgBSB6c54ijP+6ZNAWLmpP/386bkbqcy5OTcxvCq3mSXDqak9mBpwq9IZKLrabF/PejZxfKr2WCcAaO3NopciioxWE5aBGK0quzLNOzEwjoFAhwl4x7WQWQ6YqrYhyyxo+DXy+814T4CCR4Y4hLbSGYzZ6bZgi6+qOTQyuk25DILBBgP7RbcR2A0aKLejSi7oejdyes36zYAAxry7BrRTmI9ba7fiCqwruzeyOUw7joOGcFVPZuLVX2GV0rsLyEY9vDKf4eV7vyThvJQyHKQ=="; //out.println(); // decode(s,"utf-8","utf-8",null); //// // System.out.println(); // decode(s,"gbk","gbk",null); // // System.out.println(); // decode(s,"utf-8","gbk",null); // // System.out.println(); // decode(s,"gbk","utf-8",null); System.out.println(); System.out.println("s = " + s); String sDestr = decode(s,"ISO-8859-1","utf-8",null); System.out.println("sDestr = " +sDestr); sDestr = decode(s,"ISO-8859-1","gbk",null); System.out.println("sDestr = " +sDestr); // sDestr = "base=17323&pos=11&act=upgrade"; encode(sDestr,"ISO-8859-1","utf-8",null); // decode(s,"gb2312","utf-8",null); } public static String decode(String s, String sBase64Code,String sByteCode,String decoe) throws UnsupportedEncodingException{ // String s = "n52Jks/b7vqWWjD0+EL/j8X8UqV8+Y+tybEmvlGO"; // String sDecode = Base64.decode(s,sBase64Code); // String sDecode = org.apache.commons.codec.binary.Base64.decodeBase64(s); // String sDecode = new String(Base64_2.decode().decode(s.getBytes(sBase64Code))); // System.out.println(sDecode); byte[] param1 = org.apache.commons.codec.binary.Base64.decodeBase64(s.getBytes("ISO-8859-1"));// sDecode.getBytes(sBase64Code); param1 = decode(param1); // System.out.println(new String(param1,"UTF-8")); System.out.println(new String(param1,"gbk")); // System.out.println(new String(param1,"gb2312")); return new String(param1,"UTF-8"); } // public static byte[] decode(byte[] param1 ){ // byte loc_3 = 1; // byte loc_4 = 1; // byte loc_5 = 0; // byte loc_7 = 0; // // while(loc_5 < param1.length){ // int loc_6 = param1[loc_5]; // loc_6 = ~(loc_6^loc_3); // // loc_7 = (byte)( loc_3 + loc_4); // loc_3 = loc_4; // loc_4 = loc_7; // // param1[loc_5] = (byte)loc_6; // loc_5 ++; // } // return param1; // } public static byte[] decode(byte[] param1 ){ byte[] loc_2 = new byte[param1.length]; int loc_3 = 2; int loc_4 = 3; int loc_5 = 0; int loc_7 = 0; int loc_6 = 0; while(loc_5 < param1.length){ loc_6 = param1[loc_5]; loc_6 = ~(loc_6^loc_3); loc_2[loc_5] = (byte)loc_6; loc_7 = ( loc_3 + loc_4); loc_3 = loc_4; loc_4 = loc_7; loc_5 ++; } return loc_2; } public static String encode(String s, String sBase64Code,String sByteCode,String decoe) throws UnsupportedEncodingException{ byte[] param1 = s.getBytes(sBase64Code); param1 = decode(param1); // System.out.println(Base64.encode(new String(param1,"UTF-8"))); byte[] b = org.apache.commons.codec.binary.Base64.encodeBase64(param1); // System.out.println(Base64.encode(new String(param1,"gbk"))); // System.out.println(Base64.encode(new String(param1,"gb2312"))); System.out.println("b = " + new String(b)); return new String(b,"gbk"); } // public static byte[] encode(byte[] param1 ){ // // byte[] loc_4 = new byte[param1.length]; // // int loc_2 = 2; // int loc_3 = 3; // int loc_5 = 0; // int loc_6 = 0; // int loc_7 = 0; // // // while(loc_5 < param1.length){ // loc_6 = param1[loc_5]; // loc_6 = ~loc_6^loc_3; // loc_4[loc_5] = (byte)loc_6; // loc_7 = ( loc_2 + loc_3); // loc_2 = loc_3; // loc_3 = loc_7; // loc_5 ++; // } // return loc_4; // } // var _loc_6:int; // var _loc_7:int; // param1.position = 0; // var _loc_2:* = new ByteArray(); // var _loc_3:int; // var _loc_4:int; // var _loc_5:int; // while (_loc_5 < param1.length) // { // // label // _loc_6 = param1.readByte(); // _loc_6 = ~(_loc_6 ^ _loc_3); // _loc_2.writeByte(_loc_6); // _loc_7 = _loc_3 + _loc_4; // _loc_3 = _loc_4; // _loc_4 = _loc_7; // _loc_5++; // }// end while // return _loc_2; // }// end function }
存储返回类的值:
Result
package com.hry.httpclient; import java.io.UnsupportedEncodingException; import org.apache.http.Header; import org.apache.http.StatusLine; import org.apache.http.client.CookieStore; import org.apache.http.cookie.Cookie; import com.hry.base64.SendRequest2; public class Result { private StatusLine statusLine; private CookieStore cookieStore; // private HttpEntity entity; private String sContent; private Header[] headers; public String toString(){ StringBuilder sb = new StringBuilder(); // StatusLine sb.append(statusLine).append("\r\n"); // header for(Header o : headers){ sb.append(o.getName()).append("=").append(o.getValue()).append("\r\n"); } sb.append("......"); // entity try { sb.append(SendRequest2.decode(sContent,"ISO-8859-1","gbk",null)).append("\r\n"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } sb.append("......"); // Cookies for(Cookie o : cookieStore.getCookies()){ sb.append(o.getName()).append("=").append(o.getValue()).append("\r\n"); } return sb.toString(); } public String getCookie(String name){ // Cookies for(Cookie o : cookieStore.getCookies()){ if(o.getName().equalsIgnoreCase(name)){ return o.getValue(); } } return ""; } public StatusLine getStatusLine() { return statusLine; } public void setStatusLine(StatusLine statusLine) { this.statusLine = statusLine; } public CookieStore getCookieStore() { return cookieStore; } public void setCookieStore(CookieStore cookieStore) { this.cookieStore = cookieStore; } public String getsContent() { return sContent; } public void setsContent(String sContent) { this.sContent = sContent; } public Header[] getHeaders() { return headers; } public void setHeaders(Header[] headers) { this.headers = headers; } }
获取HTTPClient类 HttpConnectionManager
package com.hry.jianjun; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.params.ConnManagerParams; import org.apache.http.conn.params.ConnPerRouteBean; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; public class HttpConnectionManager { private static HttpParams httpParams; private static ClientConnectionManager connectionManager; private static DefaultHttpClient c = null; /** * 最大连接数 */ public final static int MAX_TOTAL_CONNECTIONS = 800; /** * 获取连接的最大等待时间 */ public final static int WAIT_TIMEOUT = 60000; /** * 每个路由最大连接数 */ public final static int MAX_ROUTE_CONNECTIONS = 400; /** * 连接超时时间 */ public final static int CONNECT_TIMEOUT = 10000; /** * 读取超时时间 */ public final static int READ_TIMEOUT = 10000; static { httpParams = new BasicHttpParams(); // 设置最大连接数 ConnManagerParams.setMaxTotalConnections(httpParams, MAX_TOTAL_CONNECTIONS); // 设置获取连接的最大等待时间 ConnManagerParams.setTimeout(httpParams, WAIT_TIMEOUT); // 设置每个路由最大连接数 ConnPerRouteBean connPerRoute = new ConnPerRouteBean(MAX_ROUTE_CONNECTIONS); ConnManagerParams.setMaxConnectionsPerRoute(httpParams,connPerRoute); // 设置连接超时时间 HttpConnectionParams.setConnectionTimeout(httpParams, CONNECT_TIMEOUT); // 设置读取超时时间 HttpConnectionParams.setSoTimeout(httpParams, READ_TIMEOUT); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); connectionManager = new ThreadSafeClientConnManager(httpParams, registry); } public synchronized static DefaultHttpClient getHttpClient() { if(c == null){ c = new DefaultHttpClient(connectionManager, httpParams); } return c; } }
将军具体模拟请求:JiangJunMethodOne
package com.hry.jianjun; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.CookieStore; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.params.ConnRoutePNames; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.cookie.BasicClientCookie; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import com.hry.base64.SendRequest2; import com.hry.httpclient.Result; public class JiangJunMethodOne { public Result getGongxun(String py, String p,String t, Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ // String sUrl = "http://s2.jj.ifeng.com/ifeng_s2/need.py"; StringBuilder sb = new StringBuilder(256); sb.append("http://s2.jj.ifeng.com/ifeng_s2/"+py); DefaultHttpClient client = HttpConnectionManager.getHttpClient(); // 代理 if(isPropxy){ HttpHost proxy = new HttpHost("10.36.24.20", 60001); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("p", p)); formparams.add(new BasicNameValuePair("t", t)); formparams.add(new BasicNameValuePair("e", "1")); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8"); // client.getCookieStore() this.setCookie(m, client.getCookieStore()); HttpPost post = new HttpPost(sb.toString()); post.setEntity(entity); System.out.println("url = " + post.getURI()); System.out.println("p = " + p); System.out.println("t = " + t); // 设置url?a=b&ac=b模式 // post.setEntity(new UrlEncodedFormEntity(list,"UTF-8")); //实行请求并返回 HttpResponse response = client.execute(post); // 设置返回数据 Result result = new Result(); result.setCookieStore(client.getCookieStore()); result.setsContent(EntityUtils.toString(response.getEntity())); result.setHeaders(response.getAllHeaders()); result.setStatusLine(response.getStatusLine()); // 释放 post.releaseConnection(); return result; } /** * 设置cookies值 * @param sCookies * @param Cookies */ public void setCookie( Map<String,String> m, CookieStore oCookieStore){ Iterator<String> itr = m.keySet().iterator(); while(itr.hasNext()){ String sKey = itr.next(); oCookieStore.addCookie(new BasicClientCookie(sKey,m.get(sKey))); } } public static void main(String[] args) throws ClientProtocolException, IOException, InterruptedException{ boolean isPropxy = true; JiangJunMethodOne jj = new JiangJunMethodOne(); // // // System.out.println("........getGongxun"); // String sCookies = ""; // // decode(s,"ISO-8859-1","utf-8",null); need.py // String p = SendRequest2.encode("ref=honour&base=5308", "ISO-8859-1","utf-8",null); // String t = ""; // Result rs = new JiangJunMethodOne().getGongxun("need.py",p,t, sCookies, isPropxy); // System.out.println(rs.toString()); String sCookies = "vjuids=739ce8ab0.1302fac3a1b.0.87aad6fd; ilocid=1030; ilocidflag=1; ALLYESID4=030D1FE4EA6B9F15; im_mid=p7bzP; samemappingcookie=m; prov=cn0571; city=0571; weather_city=zj_hz; py_map=1; Q37_visitedfid=284D590D144D218D428D550D618D424D141D342D161; ApV_visitedfid=149D148; ApV_dzSid=cgE6R4; smile=1D1; vjlast=1338977897.1339028331.13; _plst[_plid_]=1844039754; sid=0FA82E78B1D58885297EBA246B58D8EAhuangrongyou1; userid=1339114056959_3797; if_play_IF_GAME_HISTORY_1=jj; if_play_u=YgarsqcmgTbVQfqYkPlsmuSGrxZe; username=ifeng222859; sign=4c7833aa48355b960869f580665e8359; uid=22859; lgtime=1339113904; indulge=1; ticket=c844c747-eccb-4577-ae1e-58b4afca97ab"; Map<String,String> m = JiangJunMethodOne.cookie2Map(sCookies); System.out.println(m); //领取功勋 // int num = 10; // while(num-- > 0){ // jj.getGongxun(m, isPropxy); // Thread.sleep(1000 * 10 * 60); // } //军官培训 // jj.getTran(m, isPropxy); // 制造军队 // jj.getArmy(m, isPropxy); // 制造建筑 // jj.getbldg(m, isPropxy); // 军工生产 // jj.getJunGongShengChang(m, isPropxy); // String p = SendRequest2.encode("ref=honour&base=5308", "ISO-8859-1","utf-8",null); // 战役 jj.getZhanyi(m, isPropxy); } public void getZhanyi(Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ int num = 20; int iBegin = 178; while(num -- > 0){ String p = "hero_list=12804_133_0_6,13032_133_0_9,15384_133_-1_4,32844_232_4_7,32909_232_4_2&act=attack&pve="+iBegin+"&base=19546&pattern_list=[[3,[0,12804,0,13032,32909,32844,0,15384,0]],[4,[0,32909,0,15384,0,12804,32844,0,13032]],[5,[0,0,0,0,0,0,0,0,0]],[6,[0,0,0,0,0,0,0,0,0]],[7,[0,0,0,0,0,0,0,0,0]],[8,[0,0,0,0,0,0,0,0,0]]]&pattern=4"; p = SendRequest2.encode(p, "ISO-8859-1","utf-8",null); String t = m.get("ticket"); String py = "pve.py"; Result rs = new JiangJunMethodOne().getGongxun(py,p,t, m, isPropxy); System.out.println(rs); iBegin++; try { Thread.sleep(1000 * 120); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void getJunGongShengChang(Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ String t = m.get("ticket"); String py = "need.py"; int num = 8; while(num -- > 0){ String p = "act=make&type=1&ref=component&base=17323&incident=0"; p = SendRequest2.encode(p, "ISO-8859-1","utf-8",null); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Result rs = new JiangJunMethodOne().getGongxun(py,p,t, m, isPropxy); System.out.println(rs); } } public void getbldg(Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ String[] bases = { // "5308", // "13205", // "15759", "16368", "17323", "19546" }; String t = m.get("ticket"); String py = "bldg.py"; for(String base : bases){ for(int pos = 1; pos <= 14; pos++){ String p = "act=upgrade&base="+base+"&pos="+pos; p = SendRequest2.encode(p, "ISO-8859-1","utf-8",null); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Result rs = new JiangJunMethodOne().getGongxun(py,p,t, m, isPropxy); System.out.println(rs); } } } public void getArmy(Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ String[] bases = { "5308", "13205", "15759", "16368", "17323", "19546" }; String[] arys = { "101","202","301","402" }; String t = m.get("ticket"); String py = "army.py"; for(String base : bases){ for(String ary : arys){ int num = 1; // 普拉托 17323 ,二级坦克 if(ary.equalsIgnoreCase("202")){ if(base.equalsIgnoreCase("17323") ){ num = 5; } } while(num-- > 0){ String p = "ref=army&count=100&base="+base+"&act=recruit&army="+ary; p = SendRequest2.encode(p, "ISO-8859-1","utf-8",null); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Result rs = new JiangJunMethodOne().getGongxun(py,p,t, m, isPropxy); System.out.println(rs); } } } } public void getTran(Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ String[] ps = { "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLfrTubQA=", "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLfrXmbgY=", "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLfrPlZQA=", "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLfLThZAI=", "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLfLTuaQA=", "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLfLTvbQ0=", "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLe7fuaQU=" }; for(String p : ps){ //String p = "nJ+OypWPqe7UCnC79UusiN/gG7JvrIvziL967w=="; String t = m.get("ticket"); String py = "school.py"; try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Result rs = new JiangJunMethodOne().getGongxun(py,p,t, m, isPropxy); System.out.println(rs); } } public void getGongxun(Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ String p = "nJ+OypWPqe7UCnC79UusiN/gG7JvrIvziL967w=="; String t = m.get("ticket"); String py = "need.py"; Result rs = new JiangJunMethodOne().getGongxun(py,p,t, m, isPropxy); System.out.println(rs); } public static Map<String,String> cookie2Map(String sCookies){ Map<String,String> m = new HashMap<String,String>(); String[] ts = sCookies.split(";"); for(String o : ts){ String t = o.trim(); int idyIndex = t.indexOf("="); m.put(t.substring(0,idyIndex),t.substring(idyIndex+1, t.length())); } return m; } }
将军UI:JJUI
package com.hry.jianjun; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.CookieStore; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.params.ConnRoutePNames; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.cookie.BasicClientCookie; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import com.hry.base64.SendRequest2; import com.hry.httpclient.Result; public class JiangJunMethodOne { public Result getGongxun(String py, String p,String t, Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ // String sUrl = "http://s2.jj.ifeng.com/ifeng_s2/need.py"; StringBuilder sb = new StringBuilder(256); sb.append("http://s2.jj.ifeng.com/ifeng_s2/"+py); DefaultHttpClient client = HttpConnectionManager.getHttpClient(); // 代理 if(isPropxy){ HttpHost proxy = new HttpHost("10.36.24.20", 60001); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("p", p)); formparams.add(new BasicNameValuePair("t", t)); formparams.add(new BasicNameValuePair("e", "1")); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8"); // client.getCookieStore() this.setCookie(m, client.getCookieStore()); HttpPost post = new HttpPost(sb.toString()); post.setEntity(entity); System.out.println("url = " + post.getURI()); System.out.println("p = " + p); System.out.println("t = " + t); // 设置url?a=b&ac=b模式 // post.setEntity(new UrlEncodedFormEntity(list,"UTF-8")); //实行请求并返回 HttpResponse response = client.execute(post); // 设置返回数据 Result result = new Result(); result.setCookieStore(client.getCookieStore()); result.setsContent(EntityUtils.toString(response.getEntity())); result.setHeaders(response.getAllHeaders()); result.setStatusLine(response.getStatusLine()); // 释放 post.releaseConnection(); return result; } /** * 设置cookies值 * @param sCookies * @param Cookies */ public void setCookie( Map<String,String> m, CookieStore oCookieStore){ Iterator<String> itr = m.keySet().iterator(); while(itr.hasNext()){ String sKey = itr.next(); oCookieStore.addCookie(new BasicClientCookie(sKey,m.get(sKey))); } } public static void main(String[] args) throws ClientProtocolException, IOException, InterruptedException{ boolean isPropxy = true; JiangJunMethodOne jj = new JiangJunMethodOne(); // // // System.out.println("........getGongxun"); // String sCookies = ""; // // decode(s,"ISO-8859-1","utf-8",null); need.py // String p = SendRequest2.encode("ref=honour&base=5308", "ISO-8859-1","utf-8",null); // String t = ""; // Result rs = new JiangJunMethodOne().getGongxun("need.py",p,t, sCookies, isPropxy); // System.out.println(rs.toString()); String sCookies = "vjuids=739ce8ab0.1302fac3a1b.0.87aad6fd; ilocid=1030; ilocidflag=1; ALLYESID4=030D1FE4EA6B9F15; im_mid=p7bzP; samemappingcookie=m; prov=cn0571; city=0571; weather_city=zj_hz; py_map=1; Q37_visitedfid=284D590D144D218D428D550D618D424D141D342D161; ApV_visitedfid=149D148; ApV_dzSid=cgE6R4; smile=1D1; vjlast=1338977897.1339028331.13; _plst[_plid_]=1844039754; sid=0FA82E78B1D58885297EBA246B58D8EAhuangrongyou1; userid=1339114056959_3797; if_play_IF_GAME_HISTORY_1=jj; if_play_u=YgarsqcmgTbVQfqYkPlsmuSGrxZe; username=ifeng222859; sign=4c7833aa48355b960869f580665e8359; uid=22859; lgtime=1339113904; indulge=1; ticket=c844c747-eccb-4577-ae1e-58b4afca97ab"; Map<String,String> m = JiangJunMethodOne.cookie2Map(sCookies); System.out.println(m); //领取功勋 // int num = 10; // while(num-- > 0){ // jj.getGongxun(m, isPropxy); // Thread.sleep(1000 * 10 * 60); // } //军官培训 // jj.getTran(m, isPropxy); // 制造军队 // jj.getArmy(m, isPropxy); // 制造建筑 // jj.getbldg(m, isPropxy); // 军工生产 // jj.getJunGongShengChang(m, isPropxy); // String p = SendRequest2.encode("ref=honour&base=5308", "ISO-8859-1","utf-8",null); // 战役 jj.getZhanyi(m, isPropxy); } public void getZhanyi(Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ int num = 20; int iBegin = 178; while(num -- > 0){ String p = "hero_list=12804_133_0_6,13032_133_0_9,15384_133_-1_4,32844_232_4_7,32909_232_4_2&act=attack&pve="+iBegin+"&base=19546&pattern_list=[[3,[0,12804,0,13032,32909,32844,0,15384,0]],[4,[0,32909,0,15384,0,12804,32844,0,13032]],[5,[0,0,0,0,0,0,0,0,0]],[6,[0,0,0,0,0,0,0,0,0]],[7,[0,0,0,0,0,0,0,0,0]],[8,[0,0,0,0,0,0,0,0,0]]]&pattern=4"; p = SendRequest2.encode(p, "ISO-8859-1","utf-8",null); String t = m.get("ticket"); String py = "pve.py"; Result rs = new JiangJunMethodOne().getGongxun(py,p,t, m, isPropxy); System.out.println(rs); iBegin++; try { Thread.sleep(1000 * 120); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void getJunGongShengChang(Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ String t = m.get("ticket"); String py = "need.py"; int num = 8; while(num -- > 0){ String p = "act=make&type=1&ref=component&base=17323&incident=0"; p = SendRequest2.encode(p, "ISO-8859-1","utf-8",null); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Result rs = new JiangJunMethodOne().getGongxun(py,p,t, m, isPropxy); System.out.println(rs); } } public void getbldg(Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ String[] bases = { // "5308", // "13205", // "15759", "16368", "17323", "19546" }; String t = m.get("ticket"); String py = "bldg.py"; for(String base : bases){ for(int pos = 1; pos <= 14; pos++){ String p = "act=upgrade&base="+base+"&pos="+pos; p = SendRequest2.encode(p, "ISO-8859-1","utf-8",null); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Result rs = new JiangJunMethodOne().getGongxun(py,p,t, m, isPropxy); System.out.println(rs); } } } public void getArmy(Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ String[] bases = { "5308", "13205", "15759", "16368", "17323", "19546" }; String[] arys = { "101","202","301","402" }; String t = m.get("ticket"); String py = "army.py"; for(String base : bases){ for(String ary : arys){ int num = 1; // 普拉托 17323 ,二级坦克 if(ary.equalsIgnoreCase("202")){ if(base.equalsIgnoreCase("17323") ){ num = 5; } } while(num-- > 0){ String p = "ref=army&count=100&base="+base+"&act=recruit&army="+ary; p = SendRequest2.encode(p, "ISO-8859-1","utf-8",null); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Result rs = new JiangJunMethodOne().getGongxun(py,p,t, m, isPropxy); System.out.println(rs); } } } } public void getTran(Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ String[] ps = { "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLfrTubQA=", "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLfrXmbgY=", "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLfrPlZQA=", "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLfLThZAI=", "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLfLTuaQA=", "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLfLTvbQ0=", "n52Jks/b6vuUXDDn/lD/k9jzVL4ot4G7z7Fy8Uqfb3cLe7fuaQU=" }; for(String p : ps){ //String p = "nJ+OypWPqe7UCnC79UusiN/gG7JvrIvziL967w=="; String t = m.get("ticket"); String py = "school.py"; try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Result rs = new JiangJunMethodOne().getGongxun(py,p,t, m, isPropxy); System.out.println(rs); } } public void getGongxun(Map<String,String> m,boolean isPropxy) throws ClientProtocolException, IOException{ String p = "nJ+OypWPqe7UCnC79UusiN/gG7JvrIvziL967w=="; String t = m.get("ticket"); String py = "need.py"; Result rs = new JiangJunMethodOne().getGongxun(py,p,t, m, isPropxy); System.out.println(rs); } public static Map<String,String> cookie2Map(String sCookies){ Map<String,String> m = new HashMap<String,String>(); String[] ts = sCookies.split(";"); for(String o : ts){ String t = o.trim(); int idyIndex = t.indexOf("="); m.put(t.substring(0,idyIndex),t.substring(idyIndex+1, t.length())); } return m; } }
发表评论
-
HttpClient学习系列 -- 学习总结
2012-12-17 22:43 28320jar包: HttpClient 4.x版本 简要 ... -
HtmlParser学习系列 -- 学习总结
2012-12-16 20:53 11828引入主要包: htmlparser.jar ... -
Apache 开源软件学习
2012-10-31 21:38 968重要摘要 对象池化技术 对象池化的基本思路是: ... -
开源Java库
2012-10-18 13:06 870javassist API 第一个ja ... -
HttpClient的Demo
2012-06-03 21:54 2758HttpClientDemo 模拟凤凰的将军的登录、领 ... -
开源软件
2012-05-15 13:06 1261文章 J2EE学习中一些值得研究的开源项 ...
相关推荐
在这个“httpclient Demo 案例 含jar”中,我们将深入探讨如何使用HttpClient来处理POST请求时传递参数的字符原样问题,即避免参数被自动处理或转换。 HttpClient 4.5版本是一个稳定且广泛使用的版本,它包含了各种...
在"android httpclient demo"项目中,我们可以看到以下关键文件: - `.classpath`:包含项目的类路径信息,用于构建和运行。 - `AndroidManifest.xml`:定义应用的基本信息,如权限、活动、服务等。在这个例子中,...
这个"HttpClient Demo"工程应该包含了示例代码,展示了如何使用HttpClient进行HTTP通信。你可以从中学习到HttpClient的基本用法和高级特性,并在自己的项目中应用这些知识。通过阅读和运行这些示例,你可以更好地...
在阅读"Apache HttpClient Demo"这篇博客时,应重点关注示例代码,理解如何初始化HttpClient,构建请求,设置参数,发送请求,以及解析和处理响应。此外,还可以学习如何优化配置,如调整连接池大小,设置合适的超...
标题"C# httpClient demo"指的是一个使用C#编程语言编写的示例代码,它演示了如何使用HttpClient类进行网络请求。HttpClient是.NET Framework 4.5及更高版本中的一个类,用于处理HTTP通信,是现代、异步且高效的HTTP...
HttpClient是Apache基金会开发的一个HTTP客户端库,用于在Java应用程序中执行HTTP请求。...通过学习这个Demo,你可以深入理解HttpClient的用法,以及它如何与其他库如DOM4J配合工作,增强你的网络编程能力。
HttpClient是Apache基金会开发的一个Java库,用于执行HTTP请求。...本示例将深入讲解如何使用HttpClient进行完整的HTTP请求,同时结合JSON数据处理,因为"json...希望这个Demo能帮助你在实际项目中更好地运用HttpClient。
这是一个android的HttpClient简单demo,实现了post与get两种方式,包括完整的客户端和服务器端程序,数据库采用的是MySql数据库,数据库部分请用户自己完成,都是最简单的,我已经测试通过,这是我一天的成果,参考...
HttpClient是Java中用于发送HTTP请求的一个重要库,它允许开发者...HttpClient_Demo项目应包含一个或多个Java源文件,演示了上述知识点的实际应用,通过阅读和运行这些代码,可以更深入地理解HttpClient的使用方法。
本篇将详细介绍如何在Spring Boot项目中整合HttpClient,以及这个整合的示例(demo)所涉及的关键知识点。 首先,让我们理解Spring Boot与HttpClient的整合过程: 1. **添加依赖**:在`pom.xml`文件中,你需要引入...
本demo有两个例子test是作为服务端开启的,httpclient是客户端调用的,模拟服务端的test在启动后是没有界面的,要加上id才能看到json数据,httpclient的HttpClient33.java是测试类,最后的结果是接受到一个对象。...
jersery RestFull web service工程 应用了httpClient demo以及日志操作源码和java 动态反射机制 整个工程用来对外提供一个简化的ceph云存储服务器的restful api 同时工程作为 学习jersery 以及简单的统一日志管理 ...
在这个"httpClient4.3 Jar包 demo"中,你将找到HttpClient 4.3的jar文件以及相关的示例代码,对于学习和理解HttpClient的使用非常有帮助。 HttpClient 4.3主要知识点包括: 1. **基础概念**: - **HttpClient对象...
在本文中,我们将深入探讨HttpClient的基本用法,以及如何使用它来抓取网页内容。 首先,你需要在项目中引入HttpClient的依赖。如果你使用的是Maven,可以在pom.xml文件中添加以下依赖: ```xml <groupId>org....
4. **HttpEntity**: 表示HTTP消息的实体部分,可以是文本、二进制数据或其他内容。 5. **HttpParams**: 用于存储和管理HTTP参数,如超时、编码等。 **HttpClient详解** HttpClient是在HTTPCore之上构建的,提供了更...
首先,我们需要引入HttpClient的相关依赖。在Maven项目中,可以在pom.xml文件中添加以下依赖: ```xml <groupId>org.apache.httpcomponents <artifactId>httpclient <version>4.5.13 ``` 接下来,我们将逐步...
最后,通过`HttpClient`的`execute`方法发送请求并获取响应。 2. **Get请求**: Get请求是最简单的HTTP请求,用于从服务器获取资源。HttpClient中的`HttpGet`类可以用来创建GET请求。只需提供URL作为构造函数的...
在Java编程中,Apache HttpClient库是一个非常常用的工具,它提供了对HTTP协议的强大支持,包括GET和POST...在提供的压缩包文件中,`test-demo`和`httpclient-demo`可能包含了这些示例的源码,供你进一步学习和参考。
在这个特定的示例中,我们关注的是如何使用HttpClient来调用百度地图的API,创建一个简单的Demo。下面将详细介绍这个过程以及相关的技术知识点。 首先,你需要在项目中引入Apache HttpClient库。这可以通过Maven或...
在本示例中,我们将关注“httpclient使用post方法上传多个图片和其他参数的demo源码”,这是一个涉及到文件上传和参数传递的重要场景。 在Web开发中,POST方法常用于向服务器提交数据,比如表单数据或文件。...