方法一:注意,这个非常重要 :Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1) 没有这个别人就会屏蔽你,知道你不是浏览器!
public static void postRequest(String spec, String data) {
try {
URL url = new URL(spec);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
con.setRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");
con.setRequestProperty(
"Accept",
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*");
con.setRequestProperty("Accept-Language", "zh-cn");
con.setReq