java刷票代码_Java 刷票器

展开全部

package cn.ustb.edu.bean;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileInputStream;

import java.io.InputStreamReader;

import org.apache.commons.httpclient.Cookie;

import org.apache.commons.httpclient.HttpClient;

import org.apache.commons.httpclient.NameValuePair;

import org.apache.commons.httpclient.cookie.CookiePolicy;

import org.apache.commons.httpclient.cookie.CookieSpec;

import org.apache.commons.httpclient.methods.GetMethod;

import org.apache.commons.httpclient.methods.PostMethod;

import org.jsoup.Jsoup;

import org.jsoup.nodes.Document;

import org.jsoup.select.Elements;

public class Hello {

public static void main(String[] args) throws Exception {

File file = new File("G:/aaa.txt");

InputStreamReader read = new InputStreamReader(new FileInputStream(

file), "GBK");

BufferedReader bufferedReader = new BufferedReader(read);

String lineTXT = null;

String username = "", password = "";

String split[] = new String[2];

while ((lineTXT = bufferedReader.readLine()) != null) {

split = lineTXT.toString().trim().split("\\s{1,}");

username = split[0];

password = split[1];

// 请求认证借口,获62616964757a686964616fe4b893e5b19e31333337393033取cookie

HttpClient client = new HttpClient();

GetMethod get = new GetMethod(

"pollurl");

client.executeMethod(get);

String html = get.getResponseBodyAsString();

get.releaseConnection();

Document document = Jsoup.parse(html);

Elements element = document.select("input[name=csrf_token]");

String csrf = element.get(0).attr("value");

get.releaseConnection();

PostMethod post1 = new PostMethod(

"pollurl");

System.err.println( username+":"+password );

NameValuePair namePair[] = {

new NameValuePair("username", username ),

new NameValuePair("password", password ),

new NameValuePair("login", "1"),

new NameValuePair("csrf_token", csrf) };

post1.setRequestBody(namePair);

int state = client.executeMethod(post1);

CookieSpec cookiespec = CookiePolicy.getDefaultSpec();

Cookie[] cookies = cookiespec.match("vote.ibeike.com", 80, "",

false, client.getState().getCookies());

String coo = "";

for (Cookie cookie : cookies) {

System.out.println(cookie.toString());

coo = cookie.toString();

}

post1.releaseConnection();

PostMethod post2 = new PostMethod(

"pollurl");

NameValuePair namePair1[] = {

new NameValuePair("checked[]", "16"), // youjia

new NameValuePair("csrf_token", csrf),

new NameValuePair("isPoll", "1") };

post2.setRequestBody( namePair1 );

state = client.executeMethod(post2);

Thread.sleep(3000);

}

read.close();

}

}

追问

我看过这段,好像有点问题,而且没有界面

本回答由网友推荐

2Q==

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值