8.4 网络编程:URL

网络编程:URL

URL

  1. URI:Uniform Resource Identifier 统一资源标识符,用来标识抽象或物理资源的一个紧凑字符串。包括两种形式:URL和URN
  2. URL:Uniform Resource Locator 统一资源定位符,一种定位资源的主要访问机制的字符串,一个标准的URL必须包括:protocol、host、port、path、parameter、anchor。
  3. URN:Uniform Resource Name 统一资源名称,通过特定命名空间中的唯一名称或ID来标识资源。
  4. 一个WWW上的URL示例:http://www.google.com:80/index.html,可以看出其由四部分组成:协议–http;存放资源主机域名–www.google.com;端口号–80;资源文件名–index.html。
  5. 网络三大基石:html、http、url。

测试

code:

import java.net.MalformedURLException;
import java.net.URL;

/**
 * 测试URL:统一资源定位器
 * 1、协议
 * 2、域名 或 计算机
 * 3、端口:默认80
 * 4、请求资源
 * @author dxt
 *
 */
public class URLTest {
	public static void main(String[] args) throws MalformedURLException{
		String str1 = "https://www.hao123.com/?tn=99682755_hao_pg";
		String str2 = "https://blog.csdn.net/qq_37665301";
		//创建一个URL对象
		URL url = new URL(str2);
		//获取四个值
		System.out.println("协议:" + url.getProtocol());
		System.out.println("域名或ID:" + url.getHost());
		System.out.println("端口:" + url.getPort());
		System.out.println("请求资源1:" + url.getFile());
		System.out.println("请求资源2:" + url.getPath());
		//参数
		System.out.println("参数:" + url.getQuery());
		//锚点
		System.out.println("锚点:" + url.getRef());
	}
}

result:
result

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值