zoukankan      html  css  js  c++  java
  • URL请求响应(Socket)

    package com.socket;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.InetAddress;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.UnknownHostException;

    public class SocketTest {
    public static void main(String[] args) throws IOException {
    /*System.out.println("本机信息======");
    // 获取本地主机的InetAddress实例
    InetAddress address = InetAddress.getLocalHost();
    // 获取计算机名
    String hostName = address.getHostName();
    // 获取IP地址
    byte[] ip = address.getAddress();
    System.out.println("主机名:" + hostName);
    System.out.print("ip地址:" + ip[0]+ip[1]+ip[2]+ip[3]+" ");
    System.out.println("其他机器信息======");
    InetAddress othersAddress = InetAddress.getByName("www.runoob.com");
    byte[] othersHostName = othersAddress.getAddress();
    System.out.println(othersHostName[1]);*/
    System.out.println("url测试======");
    URL url = new URL("http://www.baidu.com");
    InputStream is = url.openStream();
    InputStreamReader isr = new InputStreamReader(is, "utf-8");
    BufferedReader br = new BufferedReader(isr);
    String data = br.readLine();
    while(data != null) {
    System.out.println(data);
    data = br.readLine();
    }
    br.close();
    isr.close();
    is.close();
    }
    }

  • 相关阅读:
    html5传感器
    html5 canvas手写字代码(兼容手机端)
    PHP pdo单例模式连接数据库
    PHP变量回收
    PHP不过过滤防止xss攻击的方法
    jquery监听回车
    jquery预加载显示百分比
    创建自己的代码仓库
    Luxurious Houses
    Vasya the Hipster
  • 原文地址:https://www.cnblogs.com/xint/p/9013747.html
Copyright © 2011-2022 走看看