16.3.1 URL(Uniform Resource Locator)
- 여러 서버들이 제공하는 자원에 접근할 수 있는 주소
- '프로토콜://호스트명:포트번호/경로명/파일명?쿼리스트링#참조'
프로토콜 : 통신규약(http)
호스트명 : 자원을 제공하는 서버이름
포트번호 : 통신에 사용되는 서버의 포트번호(80)
경로명 : 접근하려는 자원이 저장된 서버상의 위치
파일명 : 자원 이름
쿼리(query) : get, post, update, delete, ...
참조(anchor) : 참조
- method
URL(String spec)
URL(String protocol, String host, int port, String file)
URL(String protocol, String host, String file)
String getAuthority()
Object getContent()
Object getContent(Class[] classes)
int getDefaultPort()
String getFile()
String getHost()
String getPath()
int getPort()
String getProtocol()
String getQuery()
String getRef()
URLConnection openConnection()
URLConnection openConnection(Proxy proxy)
InputStream openStream()
boolean sameFile(URL other)
protected void set(String protocol, String host, int port, String file, String ref)
protected void set(String protocol, String host, int port, String authority, String userInfo, String path, String query, String ref)
String toExternalForm()String toExternalForm()
URI toURI()
import java.net.*;
class NetworkEx2 {
public static void main(String args[]) throws Exception {
URL url = new URL("http://sleepyeyes.tistory.com/admin/entry/post/?type=post&returnURL=/manage/posts/");
System.out.println("url.getAuthority() : "+ url.getAuthority());
System.out.println("url.getDefaultPort() : "+ url.getDefaultPort());
System.out.println("url.getPort() : "+ url.getPort());
System.out.println("url.getFile() : "+ url.getFile());
System.out.println("url.getHost() : "+ url.getHost());
System.out.println("url.getPath() : "+ url.getPath());
System.out.println("url.getProtocol() : "+ url.getProtocol());
System.out.println("url.getQuery() : "+ url.getQuery());
System.out.println("url.getRef() : "+ url.getRef());
System.out.println("url.getUserInfo() : "+ url.getUserInfo());
System.out.println("url.toURI() : "+ url.toURI());
}
}
/*
url.getAuthority() : sleepyeyes.tistory.com
url.getDefaultPort() : 80
url.getPort() : -1
url.getFile() : /admin/entry/post/?type=post&returnURL=/manage/posts/
url.getHost() : sleepyeyes.tistory.com
url.getPath() : /admin/entry/post/
url.getProtocol() : http
url.getQuery() : type=post&returnURL=/manage/posts/
url.getRef() : null
url.getUserInfo() : null
url.toURI() : http://sleepyeyes.tistory.com/admin/entry/post/?type=post&returnURL=/manage/posts/
*/
'자바의 정석 정리' 카테고리의 다른 글
자바의 정석 - 16.5 소켓 프로그래밍 (0) | 2022.08.31 |
---|---|
자바의 정석 - 16.4 URLConnection (0) | 2022.08.31 |
자바의 정석 - 16.2 InetAddress (0) | 2022.08.31 |
자바의 정석 - 16.1 네트워킹 (0) | 2022.08.31 |
자바의 정석 - 15.2 바이트기반 스트림 (0) | 2022.08.30 |