ScriptMethodAttribute.UseHttpGet 属性

定义

获取或设置一个值,该值指示是否通过使用 HTTP GET 调用方法。Gets or sets a value that indicates whether to invoke the method by using HTTP GET.

public:
 property bool UseHttpGet { bool get(); void set(bool value); };
public bool UseHttpGet { get; set; }
member this.UseHttpGet : bool with get, set
Public Property UseHttpGet As Boolean

属性值

Boolean

如果通过使用 HTTP GET 命令调用方法,则为 true;如果通过使用 HTTP POST 命令调用方法,则为 falsetrue if the method is invoked by using the HTTP GET command; false if the method is invoked by using the HTTP POST command. 默认值为 falseThe default is false.

示例

下面的示例演示如何将应用 ScriptMethodAttributeUseHttpGet 属性设置为的 Web 方法 trueThe following example shows how to apply ScriptMethodAttribute to a Web method with the UseHttpGet property set to true. 此代码示例是为类提供的更大示例的一部分 ScriptMethodAttributeThis code example is part of a larger example provided for the ScriptMethodAttribute class.

注解

不能在客户端上 (JavaScript) 中覆盖此属性。You cannot override this property from ECMAScript (JavaScript) on the client. 如果将此属性设置为 true ,则从脚本调用方法将始终使用 HTTP GET。If this property is set to true, invoking the method from script will always use HTTP GET.

当此属性设置为时 true ,客户端代理代码使用 HTTP GET 来调用 Web 服务。When this property is set to true, the client proxy code uses HTTP GET to call the Web service. 该方法的每个输入参数都在用于调用 Web 方法的 URL 中显示为查询参数。Each input parameter for the method appears as a query parameter in the URL that is used to invoke the Web method. 参数值是通过 JavaScript 对象表示法 (JSON) 参数值的序列化和 URL 编码获取的。The parameter value is obtained through JavaScript Object Notation (JSON) serialization and URL encoding of the parameter value.

对于任何其他 Web 交互,使用 HTTP GET 来调用 Web 服务方法遵循相同的准则。The use of HTTP GET for invoking the Web service method follows the same guidelines for any other Web interaction. HTTP GET 应仅用于未公开敏感数据的操作以及服务器操作不具有副作用的操作。HTTP GET should be used only for operations where no sensitive data is exposed and when the server action does not have side effects.

重要

如果使用 UseHttpGet 敏感数据或事务,则将属性设置为 true 可能会给应用程序带来安全风险。Setting the UseHttpGet property to true might pose a security risk for your application if you are working with sensitive data or transactions. 在 GET 请求中,浏览器将消息编码到 URL 中,因此更易于进行篡改。In GET requests, the message is encoded by the browser into the URL and is therefore an easier target for tampering.

适用于