Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » SQL Anywhere 服务器 - SQL 参考 » 系统对象 » 系统过程 » 按字母顺排序的系统过程列表

 

sa_set_http_option 系统过程

允许一个 Web 服务在结果中设置一个 HTTP 选项。

语法
sa_set_http_option( 
optname, 
val 
 )
参数
  • optname   使用此 CHAR(128) 参数指定一个字符串,该字符串包含其中一个 HTTP 选项的名称。

  • val   使用此 LONG VARCHAR 参数指定应为指定选项设置的值。

注释

在处理 Web 服务的语句或过程中使用此过程在 HTTP 结果集中设置选项。

所支持的选项为:

  • CharsetConversion   使用此选项控制是否自动将结果集从数据库的字符集转换为客户端的字符集。其值只允许为 ON 和 OFF。缺省值为 ON。请参见使用字符集自动转换

  • AcceptCharset   使用此选项指定用于 XML、SOAP 和 HTTP Web 服务的响应字符集。此选项的语法符合 RFC2616 超文本传输协议 (Hypertext Transfer Protocol) 中用于 HTTP Accept-Charset 请求标头字段说明的语法。

    要指定可接受的字符集列表,HTTP 客户端可以在发送给数据库服务器的请求中包含 Accept-Charset 请求标头。Accept-Charset 请求标头指定数据库服务器在响应时应使用哪个字符集。发送响应时,会使用客户端和数据库服务器均支持的字符集。

    未指定 Accept-Charset 请求标头时,则使用客户端最常用且受数据库服务器支持的字符集。如果客户端指定的所有字符集数据库服务器均不支持,或者未指定 Accept-Charset 请求标头,则使用数据库字符集。

    如果客户端未发送 Accept-Charset 请求标头,则数据库服务器使用 AcceptCharset 选项指定的第一个字符集。

    如果客户端指定了 Accept-Charset 请求标头,而 AcceptCharset HTTP 选项也指定了一个字符集列表,则使用客户端最常用且受数据库服务器支持的字符集。如果客户端指定的所有字符集数据库服务器均不支持,则使用 AcceptCharset HTTP 选项指定的第一个字符集。

    AcceptCharset HTTP 选项中的加号 (+) 指示数据库服务器使用数据库字符集。例如,( ‘AcceptCharset’, ‘+,UTF-8,*’)。只要有可能,就会使用 dbcharset,即便客户端倾向于使用客户端和数据库服务器均通用的字符集。在响应时使用 dbcharset 可以不必进行转换,进而改善了数据库服务器的响应时间。

    AcceptCharset HTTP 选项中的星号 (*) 指示数据库服务器使用客户端 Accept-Charset 列表中的字符集。如果不存在通用字符集,则使用 AcceptCharset 选项指定的第一个字符集。

  • SessionId   使用此选项为 HTTP 会话提供一个名称。例如,sa_set_http_option( 'SessionId', 'my_app_session_1' ) 将 HTTP 会话的 ID 设置为 my_app_session_1。SessionId 必须是非 NULL 字符串。有关 HTTP 会话的详细信息,请参见使用 HTTP 会话

  • SessionTimeout   使用此选项指定非活动期间 HTTP 会话持续的时间(单位为分钟)。当使用该会话的某个 HTTP 请求发出响应时,会重置 SessionTimeout 选项。

权限

副作用

另请参见
示例

以下示例指定如果可以接受 dbcharset,则使用它。如果无法接受 dbcharset,则指定 UTF-8 作为替代选项。如果 UTF-8 无法使用,则星号 (*) 指定客户端最常用且受数据库服务器支持的字符集:

sa_set_http_option( 'AcceptCharset', '+,UTF-8,*');

以下 pseudo 代码阐释了如何使用 AcceptCharset 选项:

if -- client sends an Accept-Charset header then
      if -- no AcceptCharset HTTP option set then
            if -- at least one of the client charsets are supported then
                  use most preferred client charset that is also supported by the server
            else
                  use dbcharset
            end if;
      else -- an AcceptCharset HTTP option was set
               if -- at least one of the client charsets is also in the HTTP option charset list 
                     and is supported by the server then use most preferred client charset that 
                     is also in the HTTP option charset list and is supported by the server(1)
              else
                     use the first charset listed in the AcceptCharset HTTP option
           end if;
     end if
else -- client did not send an Accept-Charset header
     if -- no AcceptCharset HTTP option set then
           use dbcharset
        else -- an AcceptCharset HTTP option was set
                use the first charset listed in the AcceptCharset HTTP option
        end if
end if;

以下示例将 HTTP 会话的超时时间设置为 5 分钟:

CALL sa_set_http_option('SessionTimeout', '5');