zoukankan      html  css  js  c++  java
  • java web----网络编程基础

    OSI七层模型

    InetAddress 简单使用

            InetAddress localHost = Inet4Address.getLocalHost();
            System.out.println(localHost.getHostAddress());
            System.out.println(localHost.getHostName());
    
            InetAddress byName = Inet4Address.getByName("123.56.138.186");
            System.out.println(byName);

    URL使用

            URL url = new URL("http://www.baidu.com:80/index.html?uname=xx#a");
            System.out.println("协议: "+url.getProtocol());
            System.out.println("域名: "+url.getHost());
            System.out.println("端口: "+url.getPort());
            System.out.println("请求资源: "+url.getFile());
            System.out.println("请求资源: "+url.getPath());
            System.out.println("请求参数: "+url.getQuery());
            System.out.println("请求锚点: "+url.getRef());
    

    模拟浏览器

        public static void main(String[] args) throws IOException {
            URL url = new URL("http://www.baidu.com:80/index.html?uname=xx#a");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("user-agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36");
            InputStream inputStream = conn.getInputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "gbk"));
            String msg;
            while ((msg = bufferedReader.readLine())!=null){
                System.out.println(msg);
            }
    
        }
    

      

  • 相关阅读:
    第一天开通博客,记录自己在编程道路上的点点滴滴
    一个非常棒的jQuery 评分插件--好东西要分享
    jquery.easing的使用
    SEO优化
    nodejs(三)下之mangoDB
    nodejs(三)上之express
    nodejs(二)
    nodejs(一)
    angular(二)
    angular(一)
  • 原文地址:https://www.cnblogs.com/yanxiaoge/p/11616809.html
Copyright © 2011-2022 走看看