C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet1033/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   1029   1030   1031   1032   1033   1034   1035   1036   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

WebRequest.Create( )

 has two different versions. One accepts the 

URI as a string. This is the version used by the preceding programs. The other takes the URI 

as an instance of the 



Uri

 class, which is defined in the 



System

 namespace. The 



Uri

 class 


encapsulates a URI. Using 

Uri

, you can construct a URI that can be passed to 



Create( )

. You 


can also dissect a 

Uri

, obtaining its parts. Although you don’t need to use 



Uri

 for many 

simple Internet operations, you may find it valuable in more sophisticated situations.

Uri

 defines several constructors. Two commonly used ones are shown here:

public Uri(string 

uri

)

public Uri(Uri 



base

, string 



rel

)

The first form constructs a 



Uri

 given a URI in string form. The second constructs a 



Uri

 by 


adding a relative URI specified by 

rel

 to an absolute base URI specified by 



base.

 An absolute 

URI defines a complete URI. A relative URI defines only the path.

Uri

 defines many fields, properties, and methods that help you manage URIs or that give 

you access to the various parts of a URI. Of particular interest are the properties shown here:

Property


Description

public string Host { get; }

Obtains the name of the ser ver.

public string LocalPath { get; }

Obtains the local file path.

public string PathAndQuer y { get; }

Obtains the absolute path and quer y string.

public int Por t { get; }

Obtains the por t number for the specified protocol. 

For HTTP, the por t is 80.

public string Quer y { get; }

Obtains the quer y string.

public string Scheme { get; }

Obtains the protocol.

These properties are useful for breaking a URI into its constituent parts. The following 

program demonstrates their use:

// Use Uri.

using System;

using System.Net;

www.freepdf-books.com




834

 

P a r t   I I :  



E x p l o r i n g   t h e   C #   L i b r a r y

class UriDemo {

  static void Main() {

    Uri sample = new Uri("http://HerbSchildt.com/somefile.txt?SomeQuery");

    Console.WriteLine("Host: " + sample.Host);

    Console.WriteLine("Port: " + sample.Port);

    Console.WriteLine("Scheme: " + sample.Scheme);

    Console.WriteLine("Local Path: " + sample.LocalPath);

    Console.WriteLine("Query: " + sample.Query);

    Console.WriteLine("Path and query: " + sample.PathAndQuery);

  }

}

The output is shown here:



Host: HerbSchildt.com

Port: 80


Scheme: http

Local Path: /somefile.txt

Query: ?SomeQuery

Path and query: /somefile.txt?SomeQuery




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   1029   1030   1031   1032   1033   1034   1035   1036   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish