• 发表文章


    	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();
    	}
    
    
  • 相关阅读:
    docker知识集锦
    kubernetes知识集锦
    redis知识集锦
    Java多线程知识集锦
    vscode离线安装插件
    jsoncpp的简易教程
    为什么要自动化测试?
    如何选择正确的自动化测试工具
    如何选择测试自动化工具?
    测试自动化的五大挑战
  • 原文地址:https://www.cnblogs.com/xxonehjh/p/3017069.html
Copyright © 2020-2023  润新知