본문 바로가기
개발/기본) 기본기

기본기)URL(Uniform Resource Location) Format (UriBuilder)

by 테샤르 2023. 11. 24.

URL(Uniform Resource Location) Format (UriBuilder)

URL(Uniform Resource Location) : 웹페이지, 이미지, 동영상과 같은 정보가 위치하는 유니크한 위치 정보로 URL의 구성은  다음과 같다.

<구성>

예시 URL : https://www.example.com/path/to/resource?param1=value1¶m2=value2#section1

이름 구분
프로토콜(통신규약) http://
도메인(host) www.example.com
경로(url-path) path/to/resource
넘겨주는 인자(query) param1=value1&param2=value2
section #section

 

< UriBuilder 사용 예제 -1>

using System;

class Program
{
    static void Main()
    {
        // Create a UriBuilder instance with a base URI
        UriBuilder uriBuilder = new UriBuilder("https://www.example.com");

        // Add a path to the existing URI
        uriBuilder.Path = "/path/to/resource";

        // Add a query string
        uriBuilder.Query = "param1=value1&param2=value2";

        // Add a fragment
        uriBuilder.Fragment = "section1";

        // Display the final URI
        Console.WriteLine(uriBuilder.Uri);
    }
}

 

결과
https://www.example.com/path/to/resource?param1=value1&param2=value2#section1

 

 

< UriBuilder 사용 예제 -2>

using System;

class Program
{
    static void Main()
    {
        // Create a UriBuilder instance with a base URI
		UriBuilder uriBuilder = new UriBuilder();
		uriBuilder.Scheme = "http";
		uriBuilder.Host = "www.example.com";
		uriBuilder.Path = "americas";
		uriBuilder.Port = 8089;
		uriBuilder.UserName = "admin";
		uriBuilder.Password = "secret";
		uriBuilder.Query = "search=usa";

        // Display the final URI
        Console.WriteLine(uriBuilder.Uri);
    }
}

 

결과
http://admin:secret@www.example.com:8089/americas?search=usa
 

 

 

반응형

< UriBuilder 사용 예제 -3>

using System;

class Program
{
    static void Main()
    {
        // Create a UriBuilder instance with a base URI
        UriBuilder uriBuilder = new UriBuilder();

        // Set the scheme to "file"
        uriBuilder.Scheme = "file";

        // Set the path to a file path, for example, "C:\Example\file.txt"
        uriBuilder.Path = @"C:\Example\file.txt";

        // Set the query to "action=read"
        uriBuilder.Query = "action=read";

        // Set the fragment to "section1"
        uriBuilder.Fragment = "section1";

        // Display the final URI
        Console.WriteLine(uriBuilder.Uri);
    }
}

 

결과
file:///C:/Example/file.txt?action=read#section1

 

 

★☆☆☆

 

반응형

댓글