次の方法で共有


Sys.Net.WebRequest の headers プロパティ

更新 : 2007 年 11 月

Sys.Net.WebRequest インスタンスの HTTP ヘッダーを取得します。

var headers = MyWebRequest.get_headers();

戻り値

Web 要求と共に送信された HTTP ヘッダーに含まれている名前/値ペアのディクショナリ。

解説

headers プロパティ メソッドは、カスタム ヘッダーの設定に使用できるディクショナリを返します。Web 要求に現在関連付けられているカスタム ヘッダーがない場合は、空のディクショナリが返されます。返されたディクショナリは、カスタム ヘッダー値の設定に使用できます。

使用例

HTTP ヘッダーを使用する方法の例を次に示します。このコードは、WebRequest クラスの概要で説明しているコード例の一部です。

// This function sets an HTTP header for
// the Web request.
 function WebRequestHeader() 
 {
    // Instantiate the WebRequest object.
    var wRequest =  new Sys.Net.WebRequest();

    // Set the request Url.  
    wRequest.set_url(postPage); 

    // Set the request verb.
    wRequest.set_httpVerb("POST");

    var body = "Message=Hello! Do you hear me?"
    wRequest.set_body(body);

    // Set the value of the HTTP header's "Content-Length".
    wRequest.get_headers()["Content-Length"] = body.length;

    // Set the web request completed event handler,
    // for processing return data.
    wRequest.add_completed(OnWebRequestCompletedHeader);

    // Clear the results page element.
    GetElementById("ResultsId").innerHTML = "";

    // Execute the request.
    wRequest.invoke();  
}

参照

参照

Sys.Net.WebRequestManager クラス

Sys.Net.WebRequestExecutor クラス

Sys.Net.XMLHttpExecutor クラス