Code
程序员文章站
2022-06-26 13:22:09
...
测试一下发代码
import java.io.*;
import java.net.*;
public class shuapiao {
String myurl="";//投票填写的url
String sub_gdly="http://";//投票处理的url
String session_id="";
String id="";
String proxyAddr="82.205.237.26";
int proxyPost=8080;
//HttpURLConnection conn = (HttpURLConnection)url.openConnection();
public shuapiao(String myurl){
this.myurl=myurl;
}
public String getUrl(){
String valid="";
try {
InputStream in;
Proxy proxy=new Proxy(java.net.Proxy.Type.HTTP,new InetSocketAddress
(this.proxyAddr,this.proxyPost));
URL url=new URL(myurl);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();//代理总连接不上,所以没用
//int size = conn.getHeaderFields().size();
conn.setDoOutput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");
conn.setRequestProperty("host","www");//主机地址
conn.setRequestProperty("Connection","keep-alive");//长连接,这个很好用!
//HttpURLConnection connection = (HttpURLConnection)url.openConnection();
conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");
conn.connect();
in = conn.getInputStream();
java.io.BufferedReader breader =
new BufferedReader(new InputStreamReader(in , "GBK"));
String str=breader.readLine();
while(str != null){
System.out.println(str);
if(str.indexOf("验证码:<input type=\"text\" name=\"verifycode\" size=\"4\" /><font color=
\"#0000FF\" face=\"Georgia, Times New Roman, Times, serif\" size=\"3\"><i><b>")>-1){
valid=str.substring(str.indexOf("<b>")+3, str.indexOf("</b>"));
}
str=breader.readLine();
}
String cookieval = conn.getHeaderField("set-cookie");
System.out.println(cookieval);
String sessionid=null;
if(cookieval != null){
sessionid=cookieval.substring(0,cookieval.indexOf(";"));
}
System.out.println(sessionid);
this.session_id=sessionid+"&path=/";
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return valid;
}
public void postURL(){
try {
Proxy proxy=new Proxy(java.net.Proxy.Type.HTTP,new InetSocketAddress
(this.proxyAddr,this.proxyPost));
URL url=new URL(sub_gdly);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");
conn.setRequestProperty("host","www.163.com");
conn.setRequestProperty("Connection","keep-alive");
conn.setRequestProperty("cookie", session_id.substring(0,session_id.indexOf("&")));
StringBuffer sb=new StringBuffer();
sb.append
("name=01&name=10&name=02&name=03&name=04&name=05&name=06&name=24&name=07&name=08&name1=hhhf&sex=
%C4%D0&tele=111111111&comp=111111&addr=11111&postcode=010000&verifycode=" +
this.id+"&B1=%CC%E1%BD%BB");
System.out.println(sb.toString());
OutputStream os=conn.getOutputStream();
os.write(sb.toString().getBytes("GBK"));
os.close();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
conn.connect();
String line = br.readLine();
while(line != null){
System.out.println(line);
line = br.readLine();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String args[]){
for(int i=0;i<10;i++){
shuapiao u=new shuapiao("http://");
u.id=u.getUrl();
u.postURL();
}
}
}
上一篇: $CODE$
推荐阅读
-
C#生成Code39条形码而非条形码字体的方法
-
解决Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-f8IeEI/MYSQL-python/
-
Entity Framework Code First属性映射约定
-
记录微信支付开发中的小经验(errcode = 40163; errmsg = "code been used")
-
利用Typings为Visual Studio Code实现智能提示功能
-
全新Visual Studio Code预览版0.10.10发布下载
-
Let's Code
-
ubuntu下VS code如何调试C++代码
-
详解VS Code使用之Vue工程配置format代码格式化
-
CKEditor 4.4.1 添加代码高亮显示插件功能教程【使用官方推荐Code Snippet插件】