脚本的力量:MSDN中一段代码的IronPython与PowerShell实现
生活随笔
收集整理的這篇文章主要介紹了
脚本的力量:MSDN中一段代码的IronPython与PowerShell实现
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
下面的示例說明如何創(chuàng)建 WebRequest 實例并返回響應(yīng)。 :-)
ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.NETDEVFX.v20.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()
ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.NETDEVFX.v20.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()
轉(zhuǎn)載于:https://www.cnblogs.com/yanlixin/archive/2007/08/02/840600.html
總結(jié)
以上是生活随笔為你收集整理的脚本的力量:MSDN中一段代码的IronPython与PowerShell实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: View Flash AS3 and A
- 下一篇: 蓝桥杯第八届省赛JAVA真题----k倍