WebClientProtocol.RequestEncoding 屬性

定義

用來向 XML Web 服務提出用戶端要求 Encoding

public:
 property System::Text::Encoding ^ RequestEncoding { System::Text::Encoding ^ get(); void set(System::Text::Encoding ^ value); };
public System.Text.Encoding RequestEncoding { get; set; }
[System.ComponentModel.SettingsBindable(true)]
public System.Text.Encoding RequestEncoding { get; set; }
member this.RequestEncoding : System.Text.Encoding with get, set
[<System.ComponentModel.SettingsBindable(true)>]
member this.RequestEncoding : System.Text.Encoding with get, set
Public Property RequestEncoding As Encoding

屬性值

客戶端請求的字元編碼。 預設為 null,使用底層傳輸與協定的預設編碼。

屬性

範例

下列範例是 ASP.NET Web Form,它會呼叫名為 Math的 XML Web 服務。 在函式中 EnterBtn_Click ,網頁表單明確將 RequestEncoding 設定為 UTF-8。

Important

此範例中有一個文字框可接受使用者輸入,這可能構成安全威脅。 預設情況下,ASP.NET 網頁會驗證使用者輸入中不包含腳本或 HTML 元素。 欲了解更多資訊,請參閱 腳本漏洞概述

<html>
    <script language="C#" runat="server">
       void EnterBtn_Click(Object Src, EventArgs E) 
          {
             MyMath.Math math = new MyMath.Math();
 
             // Set the Content Type to UTF-8.
             math.RequestEncoding = System.Text.Encoding.UTF8;
            
            int total = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text));
            Total.Text = "Total: " + total.ToString();
         }
 
    </script>
 
    <body>
       <form action="MathClient.aspx" runat=server>
           
          Enter the two numbers you want to add and then press the Total button.
          <p>
          Number 1: <asp:textbox id="Num1" runat=server/>  +
          Number 2: <asp:textbox id="Num2" runat=server/> =
          <asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
          <p>
          <asp:label id="Total"  runat=server/>
          
       </form>
    </body>
 </html>
<html>
    <script language="VB" runat="server">
        Sub EnterBtn_Click(Src As Object, E As EventArgs)
            Dim math As New MyMath.Math()
            
            ' Set the Content Type to UTF-8.
            math.RequestEncoding = System.Text.Encoding.UTF8
            
            Dim iTotal As Integer = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text))
            Total.Text = "Total: " & iTotal.ToString()
        End Sub
 
    </script>
 
    <body>
       <form action="MathClient.aspx" runat=server>
           
          Enter the two numbers you want to add and then press the Total button.
          <p>
          Number 1: <asp:textbox id="Num1" runat=server/>  +
          Number 2: <asp:textbox id="Num2" runat=server/> =
          <asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
          <p>
          <asp:label id="Total"  runat=server/>
          
       </form>
    </body>
 </html>

備註

決定 RequestEncoding 了請求訊息的編碼方式。 請求的 將 ContentType 以編碼值標註。

從 衍生出 WebClientProtocol 特定協定的類別,例如 SoapHttpClientProtocol SOAP 的 dos,會將此屬性設定為符合該協定的編碼要求。 例如,預設 SoapHttpClientProtocol 編碼為 UTF-8。

適用於

另請參閱