URLConnection Demo

package com.test.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public class HttpURLConnectionTest {

	public static void main(String[] args) throws IOException {

		URL url = null;

		url = new URL("https://www.baidu.com");

		if (url == null)
			return;
		URLConnection connection = url.openConnection();	
		connection.setDoInput(true);
		connection.setDoOutput(true);
		connection.setUseCaches(false);
		//connection.connect();//并未起到作用
		OutputStream out = connection.getOutputStream();
		InputStream in = connection.getInputStream();
		int c = -1;
		while((c = in.read()) != -1){
			System.out.print((char)c);
		}
		System.out.println();
		in.close();
		out.close();
		
		HttpURLConnection httpUC = new HttpURLConnection(url) {

			@Override
			public void disconnect() {

			}

			@Override
			public boolean usingProxy() {

				return false;
			}

			@Override
			public void connect() throws IOException {

			}

		};

	}

}




    
    
    
    页é¢ä¸å­å¨_ç¾åº¦æç´¢
    



    

å¾æ±æ­ï¼æ¨è¦è®¿é®ç页é¢ä¸å­å¨ï¼

温馨æ示ï¼

  1. 请æ£æ¥æ¨è®¿é®çç½åæ¯å¦æ­£ç¡®
  2. å¦ææ¨ä¸è½ç¡®è®¤è®¿é®çç½åï¼è¯·æµè§ç¾åº¦æ´å¤é¡µé¢æ¥çæ´å¤ç½åã
  3. åå°é¡¶é¨éæ°åèµ·æç´¢
  4. å¦æä»»ä½æè§æ建议ï¼è¯·åæ¶åé¦ç»æ们ã


你可能感兴趣的:(Java)