public static void setConnection(HttpURLConnection connect) { connect.setRequestProperty("Accept", "*/*"); connect.setRequestProperty( "cookie", ".DottextCookie=验证字符"); connect.setRequestProperty("referer", "http://www.cnblogs.com/"); connect.setRequestProperty("User-Agent", " Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0"); } public static void readContent(HttpURLConnection connect) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader( connect.getInputStream(), "utf-8")); while (reader.ready()) { System.out.println(reader.readLine()); } reader.close(); } public static void readUserInfo() throws IOException { URL getUrl = new URL( "http://passport.cnblogs.com/user/LoginInfo?callback=jQuery1705454300473020005_1365753853884&_=1365753854051"); HttpURLConnection connect = (HttpURLConnection) getUrl .openConnection(); setConnection(connect); connect.connect(); readContent(connect); connect.disconnect(); } public static void postShortMsg() throws IOException { URL getUrl = new URL("http://home.cnblogs.com/ajax/ing/Publish"); HttpURLConnection connection = (HttpURLConnection) getUrl .openConnection(); setConnection(connection); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod("POST"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); connection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); connection.connect(); DataOutputStream out = new DataOutputStream( connection.getOutputStream()); String content = "{\"content\":\"天天运动\",\"publicFlag\":0}"; out.write(content.getBytes("utf-8")); out.flush(); out.close(); readContent(connection); connection.disconnect(); } public static void postNote(String title, String send_content) throws IOException { URL getUrl = new URL( "http://www.cnblogs.com/xxonehjh/admin/EditPosts.aspx?opt=1"); HttpURLConnection connection = (HttpURLConnection) getUrl .openConnection(); setConnection(connection); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod("POST"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); String content = "__VIEWSTATE=" + "&Editor%24Edit%24txbTitle=" + URLEncoder.encode(title, "utf-8") + "&Editor%24Edit%24EditorBody=" + URLEncoder.encode(send_content, "utf-8") + "&Editor%24Edit%24APOptions%24APSiteHome%24chkDisplayHomePage=on" + "&Editor%24Edit%24Advanced%24ckbPublished=on" + "&Editor%24Edit%24Advanced%24chkComments=on" + "&Editor%24Edit%24Advanced%24chkMainSyndication=on" + "&Editor%24Edit%24Advanced%24txbEntryName=" + "&Editor%24Edit%24Advanced%24txbExcerpt=" + "&Editor%24Edit%24Advanced%24txbTag=" + "&Editor%24Edit%24Advanced%24tbEnryPassword=" + "&Editor%24Edit%24lkbPost=%E5%8F%91%E5%B8%83"; byte[] data = content.getBytes("utf-8"); connection.setRequestProperty("Content-Length", "" + data.length); connection.connect(); DataOutputStream out = new DataOutputStream( connection.getOutputStream()); out.write(data); out.flush(); out.close(); readContent(connection); connection.disconnect(); }