HttpURLConnect秒杀程序

package cn.wingware;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Properties;

public class Wing {

public static void main(String args[])throws Exception{
while(true){
byte[] b = check();
System.out.println("=====:"+new String(b));
}
}


public static byte[] check() throws Exception {
Properties prop = System.getProperties();
// 设置http访问要使用的代理服务器的地址
prop.setProperty("http.proxyHost", "10.99.60.201");
// 设置http访问要使用的代理服务器的端口
prop.setProperty("http.proxyPort", "8080");
String URLName = "http://www.6663.com/api/tb.php?r=" + Math.random();
String cookie = "PHPSESSID=6caacac986538f45e09427b5202b30fe; skl_patcount=2403; skl_auth=5e236rgftq%2Bp9AqdSa3y53L8f6cw%2FRSOZql1za7g0awLgkVxeTL5KWgUCQ8GWez3%2BVqd7qsDXhdQaPuKRbRiBfkqAy3vciBcDDrbir3MBjP9gA8WR5BpPHirbkiT2bPOkDTOR4Ei; skl_uinfo=60043%09wingware%090%090%090%0914%090";
// System.out.println(URLName);
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(URLName).openConnection();
httpURLConnection.setDoOutput(false);
// Read from the connection. Default is true.
// httpURLConnection.setDoInput(true);
// Set the post method. Default is GET
// httpURLConnection.setRequestMethod("get");
// Post cannot use caches
// Post 请求不能使用缓存
// httpURLConnection.setUseCaches(false);
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpURLConnection.setRequestProperty("Host", "www.6663.com");
httpURLConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16");
httpURLConnection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
httpURLConnection.setRequestProperty("Accept-Language", "zh-cn,zh;q=0.5");
httpURLConnection.setRequestProperty("Accept-Encoding", "gzip,deflate");
httpURLConnection.setRequestProperty("Accept-Charset", "GB2312,utf-8;q=0.7,*;q=0.7");
httpURLConnection.setRequestProperty("Keep-Alive", "115");
httpURLConnection.setRequestProperty("Proxy-Connection", "keep-alive");
httpURLConnection.setRequestProperty("Pragma","no-cache");
httpURLConnection.setRequestProperty("Cache-Control","no-cache");
httpURLConnection.setRequestProperty("Referer", "http://www.6663.com/experience.php");
httpURLConnection.setRequestProperty("Cookie", cookie);

// 设置连接属性
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);

OutputStream out = httpURLConnection.getOutputStream();
out.write("type=1&a=2414&b=1304392440575".getBytes());

// httpURLConnection.setUseCaches(false);
InputStream in = httpURLConnection.getInputStream();
byte[] b = new byte[in.available()];
in.read(b);
// String jsonData = new String(b, "GBK");
return b;
// JSONObject jsonObject = JSONObject.fromObject(jsonData);
// System.out.println(jsonObject.get("result") + "-" +
// jsonObject.get("reason"));
}

}

你可能感兴趣的:(PHP,windows,.net,cache,firefox)