http_request
http_request — 独自のリクエストを実行する
説明
string http_request ( int method [, string url [, string body [, array options [, array &info]]]] )指定した url に対して独自の HTTP リクエストを実行します。
使用可能なパラメータおよびオプションの一覧は、 http_get() を参照ください。
パラメータ
- method
-
リクエストメソッド。
- url
-
URL。
- body
-
リクエストの本文。
- options
-
リクエストのオプション
- info
-
リクエスト/レスポンス の情報
返り値
成功した場合は HTTP レスポンスを文字列で、失敗した場合は FALSE を返します。HttpRequest クラス
アセンブリ: System.Web (system.web.dll 内)


HttpRequest クラスのメソッドとプロパティは、HttpApplication、HttpContext、Page、および UserControl の各クラスの Request プロパティによって公開されます。

StreamWriter クラスを使用して、HttpRequest クラスの複数のプロパティ値をファイルに書き込むコード例を次に示します。文字列型のプロパティの場合、ファイルに書き込むときに値が HTML エンコードされます。コレクションを表すプロパティでは、格納されているキーと値の各ペアがループ処理でファイルに書き込まれます。
<%@ Page Language="VB" %> <%@ import Namespace="System.Threading" %> <%@ import Namespace="System.IO" %> <script runat="server"> ' NOTE: To use this sample, create a c:\temp\CS folder, ' add the ASP.NET account (in IIS 5.x <machinename>\ASPNET , ' in IIS 6.x NETWORK SERVICE), and give it write permissions ' to the folder. Private Const INFO_DIR As String = "c:\temp\VB\RequestDetails" Public Shared requestCount As Integer Private Sub Page_Load(sender As Object, e As System.EventArgs) ' Create a variable to use when iterating ' through the UserLanguages property. Dim langCount As Integer ' Create a counter to name the file. Dim requestNumber As Integer = _ Interlocked.Increment(requestCount) ' Create the file to contain information about the request. Dim strFilePath As String = INFO_DIR & requestNumber.ToString() & ".txt" Dim sw As StreamWriter = File.CreateText(strFilePath) Try ' Write request information to the file with HTML encoding. sw.WriteLine(Server.HtmlEncode(DateTime.Now.ToString())) sw.WriteLine(Server.HtmlEncode(Request.CurrentExecutionFilePath)) sw.WriteLine(Server.HtmlEncode(Request.ApplicationPath)) sw.WriteLine(Server.HtmlEncode(Request.FilePath)) sw.WriteLine(Server.HtmlEncode(Request.Path)) ' Iterate through the Form collection and write ' the values to the file with HTML encoding. For Each s As String In Request.Form sw.WriteLine("Form: " & Server.HtmlEncode(s)) Next s ' Write the PathInfo property value ' or a string if it is empty. If Request.PathInfo = String.Empty Then sw.WriteLine("The PathInfo property contains no information.") Else sw.WriteLine(Server.HtmlEncode(Request.PathInfo)) End If ' Write request information to the file with HTML encoding. sw.WriteLine(Server.HtmlEncode(Request.PhysicalApplicationPath)) sw.WriteLine(Server.HtmlEncode(Request.PhysicalPath)) sw.WriteLine(Server.HtmlEncode(Request.RawUrl)) ' Write a message to the file dependent upon ' the value of the TotalBytes property. If Request.TotalBytes > 1000 Then sw.WriteLine("The request is 1KB or greater") Else sw.WriteLine("The request is less than 1KB") End If ' Write request information to the file with HTML encoding. sw.WriteLine(Server.HtmlEncode(Request.RequestType)) sw.WriteLine(Server.HtmlEncode(Request.UserHostAddress)) sw.WriteLine(Server.HtmlEncode(Request.UserHostName)) sw.WriteLine(Server.HtmlEncode(Request.HttpMethod)) ' Iterate through the UserLanguages collection and ' write its HTML encoded values to the file. For langCount = 0 To Request.UserLanguages.Length - 1 sw.WriteLine("User Language " & langCount.ToString() & _ ": " & Server.HtmlEncode( _ Request.UserLanguages(langCount))) Next Finally ' Close the stream to the file. sw.Close() End Try lblInfoSent.Text = _ "Information about this request has been sent to a file." End Sub 'Page_Load Private Sub btnSendInfo_Click(sender As Object, e As System.EventArgs) lblInfoSent.Text = _ "Hello, " & Server.HtmlEncode(txtBoxName.Text) & _ ". You have created a new request info file." End Sub 'btnSendInfo_Click </script> <html> <head> </head> <body> <form runat="server"> <p> </p> <p> Enter your hame here: <asp:TextBox id="txtBoxName" runat="server"></asp:TextBox> </p> <p> <asp:Button id="btnSendInfo" onclick="btnSendInfo_Click" runat="server" Text="Click Here"></asp:Button> </p> <p> <asp:Label id="lblInfoSent" runat="server"></asp:Label> </p> </form> </body> </html>
<%@ Page Language="C#" %> <%@ import Namespace="System.Threading" %> <%@ import Namespace="System.IO" %> <script runat="server"> /* NOTE: To use this sample, create a c:\temp\CS folder, * add the ASP.NET account (in IIS 5.x <machinename>\ASPNET , * in IIS 6.x NETWORK SERVICE), and give it write permissions * to the folder.*/ private const string INFO_DIR = @"c:\temp\CS\RequestDetails"; public static int requestCount; private void Page_Load(object sender, System.EventArgs e) { // Create a variable to use when iterating // through the UserLanguages property. int langCount; int requestNumber = Interlocked.Increment(ref requestCount); // Create the file to contain information about the request. string strFilePath = INFO_DIR + requestNumber.ToString() + @".txt"; StreamWriter sw = File.CreateText(strFilePath); try { // Write request information to the file with HTML encoding. sw.WriteLine(Server.HtmlEncode(DateTime.Now.ToString())); sw.WriteLine(Server.HtmlEncode(Request.CurrentExecutionFilePath)); sw.WriteLine(Server.HtmlEncode(Request.ApplicationPath)); sw.WriteLine(Server.HtmlEncode(Request.FilePath)); sw.WriteLine(Server.HtmlEncode(Request.Path)); // Iterate through the Form collection and write // the values to the file with HTML encoding. // String[] formArray = Request.Form.AllKeys; foreach (string s in Request.Form) { sw.WriteLine("Form: " + Server.HtmlEncode(s)); } // Write the PathInfo property value // or a string if it is empty. if (Request.PathInfo == String.Empty) { sw.WriteLine("The PathInfo property contains no information."); } else { sw.WriteLine(Server.HtmlEncode(Request.PathInfo)); } // Write request information to the file with HTML encoding. sw.WriteLine(Server.HtmlEncode(Request.PhysicalApplicationPath)); sw.WriteLine(Server.HtmlEncode(Request.PhysicalPath)); sw.WriteLine(Server.HtmlEncode(Request.RawUrl)); // Write a message to the file dependent upon // the value of the TotalBytes property. if (Request.TotalBytes > 1000) { sw.WriteLine("The request is 1KB or greater"); } else { sw.WriteLine("The request is less than 1KB"); } // Write request information to the file with HTML encoding. sw.WriteLine(Server.HtmlEncode(Request.RequestType)); sw.WriteLine(Server.HtmlEncode(Request.UserHostAddress)); sw.WriteLine(Server.HtmlEncode(Request.UserHostName)); sw.WriteLine(Server.HtmlEncode(Request.HttpMethod)); // Iterate through the UserLanguages collection and // write its HTML encoded values to the file. for (langCount=0; langCount < Request.UserLanguages.Length; langCount++) { sw.WriteLine(@"User Language " + langCount +": " + Server.HtmlEncode(Request.UserLanguages[langCount])); } } finally { // Close the stream to the file. sw.Close(); } lblInfoSent.Text = "Information about this request has been sent to a file."; } private void btnSendInfo_Click(object sender, System.EventArgs e) { lblInfoSent.Text = "Hello, " + Server.HtmlEncode(txtBoxName.Text) + ". You have created a new request info file."; } </script> <html> <head> </head> <body> <form runat="server"> <p> </p> <p> Enter your hame here: <asp:TextBox id="txtBoxName" runat="server"></asp:TextBox> </p> <p> <asp:Button id="btnSendInfo" onclick="btnSendInfo_Click" runat="server" Text="Click Here"></asp:Button> </p> <p> <asp:Label id="lblInfoSent" runat="server"></asp:Label> </p> </form> </body> </html>


System.Web.HttpRequest


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HttpRequest コンストラクタ
アセンブリ: System.Web (system.web.dll 内)

Dim filename As String Dim url As String Dim queryString As String Dim instance As New HttpRequest(filename, url, queryString)

HttpRequest クラスのインスタンスを独自に作成する必要はありません。HttpRequest クラスのメソッドとプロパティは、HttpApplication、HttpContext、Page、UserControl の各クラスの Request プロパティによって公開されます。

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HttpRequest プロパティ


HttpRequest メソッド

名前 | 説明 | |
---|---|---|
![]() | BinaryRead | 現在の入力ストリームから、指定したバイト数のバイナリ読み取りを実行します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | MapImageCoordinates | インカミング イメージ フィールド フォーム パラメータを、該当する x 座標値および y 座標値に割り当てます。 |
![]() | MapPath | オーバーロードされます。 要求された URL の仮想パスを、現在の要求に対するサーバー上の物理パスに割り当てます。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | SaveAs | HTTP 要求をディスクに保存します。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
![]() | ValidateInput | Cookies、Form、および QueryString の各プロパティを通じてアクセスするコレクションに対して検証を実行します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

HttpRequest メンバ
Web 要求中にクライアントから送信された HTTP 値を ASP.NET で読み取ることができるようにします。
HttpRequest データ型で公開されるメンバを以下の表に示します。



名前 | 説明 | |
---|---|---|
![]() | BinaryRead | 現在の入力ストリームから、指定したバイト数のバイナリ読み取りを実行します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | MapImageCoordinates | インカミング イメージ フィールド フォーム パラメータを、該当する x 座標値および y 座標値に割り当てます。 |
![]() | MapPath | オーバーロードされます。 要求された URL の仮想パスを、現在の要求に対するサーバー上の物理パスに割り当てます。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | SaveAs | HTTP 要求をディスクに保存します。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
![]() | ValidateInput | Cookies、Form、および QueryString の各プロパティを通じてアクセスするコレクションに対して検証を実行します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- HttpRequestのページへのリンク