WebClientProtocol.RequestEncoding 属性

定义

用于对 XML Web services 发出客户端请求的 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 窗体,它调用名为 的 MathXML Web 服务。 EnterBtn_Click在 函数中,Web 窗体将 RequestEncoding 显式设置为 UTF-8。

重要

此示例具有一个接受用户输入的文本框,这是一个潜在的安全威胁。 默认情况下,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 的 ),将此属性设置为符合特定协议的编码要求。 例如, SoapHttpClientProtocol 将默认编码设置为 UTF-8。

适用于

另请参阅