关于httpClient4.3,实现自动投注功能的问题

ljt0000mf 2014-11-17 03:45:15
最近对httpclient比较感兴趣,想针对一个网站写一个自动投注的程序,网站登录需要的用户名和密码及其它信息,在代码里有。


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;


public class CopyOfTest {
private static String userName = "woaihuoqiu1@163.com";
private static String password = "1qaz2wsx";
private static String url = "http://www.juxiangyou.com/login.php?act=loginDo";
private static String put28url ="http://game.juxiangyou.com//luck28/betting.php?a=664271";

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

public static void postLogin() throws ClientProtocolException, IOException{
//第一次,登录主页
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("tbUserAccount", userName));
nvps.add(new BasicNameValuePair("tbUserPwd", password));
nvps.add(new BasicNameValuePair("isChkCode", "0"));
httpPost.setEntity(new UrlEncodedFormEntity(nvps));

CloseableHttpResponse response = httpclient.execute(httpPost);
try {
System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();

String loginEntityContent = EntityUtils.toString(entity);
System.out.println(loginEntityContent);
if (loginEntityContent.contains("result\":200")) {//登录成功
System.out.println("loginEntityContent true");
//登录成功后,进行自动投注
HttpPost httpPost1 = new HttpPost(put28url);

nvps = getParams2();//设置post提交参数,就是这里有问题,不知设置哪些参数
httpPost1.setEntity(new UrlEncodedFormEntity(nvps));

CloseableHttpResponse lucky28resp = httpclient.execute(httpPost1);
entity = lucky28resp.getEntity();
loginEntityContent = EntityUtils.toString(entity,"gb2312");
System.out.println(loginEntityContent);
}

EntityUtils.consume(entity);
} finally {
response.close();
}

}



public static ArrayList <NameValuePair> getParams(){
ArrayList <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("tbLuck28Chk[0]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[1]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[2]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[3]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[4]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[5]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[6]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[7]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[8]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[9]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));//10

nvps.add(new BasicNameValuePair("tbLuck28Chk[10]", "on"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", "1"));
nvps.add(new BasicNameValuePair("tbLuck28Chk[11]", "on"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", "1"));
nvps.add(new BasicNameValuePair("tbLuck28Chk[12]", "on"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", "1"));
nvps.add(new BasicNameValuePair("tbLuck28Chk[13]", "on"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", "1"));
nvps.add(new BasicNameValuePair("tbLuck28Chk[14]", "on"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", "1"));
nvps.add(new BasicNameValuePair("tbLuck28Chk[15]", "on"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", "1"));
nvps.add(new BasicNameValuePair("tbLuck28Chk[16]", "on"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", "1"));
nvps.add(new BasicNameValuePair("tbLuck28Chk[17]", "on"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", "1"));// 8

nvps.add(new BasicNameValuePair("tbLuck28Chk[18]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[19]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[20]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[21]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[22]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[23]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[24]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[25]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[26]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Chk[27]", "off"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));//10

return nvps;
}

public static ArrayList <NameValuePair> getParams1(){
ArrayList <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("tbLuck28Chk[0]", "on"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", "10"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));//10

nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));// 8

nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", ""));//10

return nvps;
}

public static ArrayList <NameValuePair> getParams2(){
ArrayList <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("tbLuck28Chk[0]", "on"));
nvps.add(new BasicNameValuePair("tbLuck28Value[]", "10"));

return nvps;
}


}



程序的功能是,首先登录网站,登录成功后,直接调用自动投注的地址,就是put28url,这是一个在Form里的,通过post传送的地址。下面是我用HttpAnalyzerStdV7 拦截post请求的参数



执行,我的程序后,返回结果是提示信息:U豆不足(U豆就是投注单位),可实际上是足够的。
我怀疑的是我的post参数传递的不对,代码里,我试验了三种方式,都不行。
不知错在哪里,请各位高手指教,非常感谢了
...全文
778 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiangao316066 2014-11-19
  • 打赏
  • 举报
回复
你的账号U豆确实是0,你看错了
ljt0000mf 2014-11-19
  • 打赏
  • 举报
回复
引用 4 楼 chuxingzhe 的回复:
你的账号密码确实可以登录
晕,有解决方案没。 高手来吧,来吧。来吧。。。
chuxingzhe 2014-11-18
  • 打赏
  • 举报
回复
你的账号密码确实可以登录
ljt0000mf 2014-11-18
  • 打赏
  • 举报
回复
晕,怎么没人啊,自己顶, 知道的来帮忙看看吧
ljt0000mf 2014-11-17
  • 打赏
  • 举报
回复
对。http://game.juxiangyou.com//luck28/betting.php?a=664271"; 最后,a=664271,这个根据期号不同,a后面的值会不同的,大家试验时,请改成当前或以后的号, 不然,会提示投注已经截止。
ljt0000mf 2014-11-17
  • 打赏
  • 举报
回复
这是post参数图片 Parameter Name Value tbLuck28Chk[0] on tbLuck28Value[] 10 tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] tbLuck28Value[] 这是post参数 我只选择了第一个,投了10注。一共有28个,其它的27个都没有投

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧