Script power: ironpython and powershell implementation of a piece of code in msdn

Source: Internet
Author: User
The following example shows how to create a webrequest instance and return a response.
MS-help: // Ms. msdnqtr. v80.chs/ms. msdn. v80/ms. netdevfx. v1_chs/cpref10/html/t_system_net_webrequest.htm
C #
Using system;
Using system. IO;
Using system. net;
Using system. text;

Namespace examples. system. net
{
Public class webrequestgetexample
{
Public static void main ()
{
// Create a request for the URL.
Webrequest request = webrequest. Create ("http://www.contoso.com/default.html ");
// If required by the server, set the credentials.
Request. Credentials = credentialcache. defaultcredentials;
// Get the response.
Httpwebresponse response = (httpwebresponse) request. getresponse ();
// Display the status.
Console. writeline (response. statusdescription );
// Get the Stream Containing content returned by the server.
Stream datastream = response. getresponsestream ();
// Open the stream using a streamreader for easy access.
Streamreader reader = new streamreader (datastream );
// Read the content.
String responsefromserver = reader. readtoend ();
// Display the content.
Console. writeline (responsefromserver );
// Cleanup the streams and the response.
Reader. Close ();
Datastream. Close ();
Response. Close ();
}
}
}

Ironpython

From system import *
From system. Io import *
From system. net import *
From system. Text import *
Request = webrequest. Create ("http://www.contoso.com/default.html ")
Response = request. getresponse ()
Console. writeline (response. statusdescription)
Datastream = response. getresponsestream ()
Reader = streamreader (datastream)
Responsefromserver = reader. readtoend ()
Console. writeline (responsefromserver)
Reader. Close ()
Datastream. Close ()
Response. Close ()

Powershell

$ Request = [system. net. webrequest]: Create ("http://www.contoso.com/default.html ");
$ Request. Credentials = [system. net. credentialcache]: defaultcredentials
$ Response = $ request. getresponse ()
[System. Console]: writeline ($ response. statusdescription)
$ Datastream = $ response. getresponsestream ()
$ Reader = new-Object System. Io. streamreader ($ datastream)
$ Responsefromserver = $ reader. readtoend ()
[System. Console]: writeline ($ responsefromserver)
$ Reader. Close ()
$ Datastream. Close ()
$ Response. Close ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.