C# 0 The Complete Reference


PART II C h a p t e r   2 5



Download 4,07 Mb.
Pdf ko'rish
bet1044/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   1040   1041   1042   1043   1044   1045   1046   1047   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART II

C h a p t e r   2 5 :  

N e t w o r k i n g   T h r o u g h   t h e   I n t e r n e t   U s i n g   S y s t e m . N e t    

843


class WebClientDemo {

  static void Main() {

    WebClient user = new WebClient();

    string uri = "http://www.McGraw-Hill.com";

    string fname = "data.txt";

    try {

      Console.WriteLine("Downloading data from " +

                        uri + " to " + fname);

      user.DownloadFile(uri, fname);

    } catch (WebException exc) {

      Console.WriteLine(exc);

    }


    Console.WriteLine("Download complete.");

  }


}

Property


Description

public string BaseAddress { get; set; }

Obtains or sets the base address of the desired 

URI. If this proper ty is set, then addresses 

specified by the 

WebClient

 methods will be 

relative to the base address.

public RequestCachePolicy

    CachePolicy { get; set; }

Obtains or sets the policy that determines when 

the cache is used. 

public ICredentials Credentials { get; set; }

Obtains or sets authentication information. This 

proper ty is null by default.

public Encoding Encoding { get; set; }

Obtains or sets the character encoding used while 

transferring strings. 

public WebHeaderCollection

      Headers{ get; set; }

Obtains or sets the collection of the request 

headers.


public bool IsBusy( get; }

If the request is still transferring information, this 

proper ty is true. It is false other wise. 

public IWebProxy Proxy { get; set; }

Obtains or sets the proxy. 

public NameValueCollection

     Quer yString { get; set; }

Obtains or sets a quer y string consisting of name/

value pairs that can be attached to a request. The 

quer y string is separated from the URI by a 

?

. If 


more than one name/value pair exists, then an @ 

separates each pair.

public WebHeaderCollection

    ResponseHeaders{ get; }

Obtains a collection of the response headers.

public bool UseDefaultCredentials { get; set; }

Obtains or sets a value that determines if default 

credentials are used for authentication. If true, 

the default credentials (i.e., those of the user) 

are used. They are not used if false.

T

ABLE


 25-6 

The Proper ties Defi ned by 

WebClient

www.freepdf-books.com




844

 

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

Method


Description

public byte[ ] DownloadData(string 



uri

)

Downloads the information at the URI specified by 



uri

 and 


returns the result in an array of bytes.

public byte[ ] DownloadData(Uri 



uri

)

Downloads the information at the URI specified by 



uri

 and 


returns the result in an array of bytes. 

public void

    DownloadFile(string 

uri

, string 



fname

)

Downloads the information at the URI specified by 



uri

 and 


stores the result in the file specified by 

fname.

public void

    DownloadFile(Uri 

uri

, string 



fname

)

Downloads the information at the URI specified by 



uri

 and 


stores the result in the file specified by 

fname.

public string DownloadString(string 



uri

)

Downloads the information at the URI specified by 



uri

 and 


returns the result as a 

string


.

public string DownloadString(Uri 



uri

)

Downloads the information at the URI specified by 



uri

 and 


returns the result as a 

string


.

public Stream OpenRead(string 



uri

)

Returns an input stream from which the information at 



the URI specified by 

uri

 can be read. This stream must be 

closed after reading is completed.

public Stream OpenRead(Uri 



uri

)

Returns an input stream from which the information at 



the URI specified by 

uri

 can be read. This stream must be 

closed after reading is completed.

public Stream OpenWrite(string 



uri

)

Returns an output stream to which information can be 



written to the URI specified by 

uri.

 This stream must be 

closed after writing is completed.

public Stream OpenWrite(Uri 



uri

)

Returns an output stream to which information can be 



written to the URI specified by 

uri.

 This stream must be 

closed after writing is completed.

public Stream OpenWrite(string 



uri

, string 



how

)

Returns an output stream to which information can be 



written to the URI specified by 

uri.

 This stream must be 

closed after writing is completed. The string passed in 

how

specifies how the information will be written.

public Stream OpenWrite(Uri 

uri

, string 



how

)

Returns an output stream to which information can be 



written to the URI specified by 

uri.

 This stream must be 

closed after writing is completed. The string passed in 

how

specifies how the information will be written.

public byte[ ]

    UploadData(string 



uri

, byte[ ] 



info

)

Writes the information specified by 



info

 to the URI specified 

by

uri.

 The response is returned.

public byte[ ]

    UploadData(Uri 



uri

, byte[ ] 



info

)

Writes the information specified by 



info

 to the URI specified 

by

uri.

 The response is returned. 

public byte[ ]

    UploadData(string 



uri

,

                     string 



how

,

                     byte[ ] 



info

)

Writes the information specified by 



info

 to the URI specified 

by

uri.

 The response is returned. The string passed in 



how

specifies how the information will be written.

T

ABLE


 25-7 

The Synchronous Methods Defi ned by 

WebClient

This program downloads the information at McGrawHill.com and puts it into a file called 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   1040   1041   1042   1043   1044   1045   1046   1047   ...   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