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

SAP Sybase SQL Anywhere 16.0 (中文) » SQL Anywhere 服务器 - 编程 » HTTP Web 服务 » 使用 Web 客户端访问 Web 服务 » Web 客户端应用程序开发 » Web 客户端函数和过程的要求和建议

 

HTTP 请求标头管理

HTTP 请求标头可以用 CREATE PROCEDURE 和 CREATE FUNCTION 语句的 HEADER 子句来添加、更改或删除。通过引用名称来取消 HTTP 请求标头。可以通过在标头名称后加上冒号并紧跟值来添加或更改 HTTP 请求标头的值。标头值的规范是可选的。

例如,在 Web 客户端数据库中执行以下 SQL 语句来创建名为 SomeOperation2 的过程,该过程向指定的 URL(限制 HTTP 请求标头)发送请求:

CREATE PROCEDURE SomeOperation2()
    URL 'HTTP://localhost:8082/dbname/SampleWebService'
    TYPE 'HTTP:GET'
    HEADER 'SOAPAction\nDate\nFrom:\nCustomAlias:John Doe';

在本例中,由 SQL Anywhere 自动生成的标头 Date 被取消。From 标头存在,但没有指派任何值。HTTP 请求包含了名为 CustomAlias 的新标头,并指派了值 John Doe。GET 请求与下列内容类似:

GET /dbname/SampleWebService HTTP/1.0
ASA-Id: e88a416e24154682bf81694feaf03052
User-Agent: SQLAnywhere/16.0.0.1403
Accept-Charset: windows-1252, UTF-8, *
From: 
Host: localhost:8082
Connection: close
CustomAlias: John Doe

支持长标头值的折叠,只要一个或多个空格后面紧跟 \n

下面的示例演示了对长标头值的支持:

CREATE PROCEDURE SomeOperation3()
    URL 'HTTP://localhost:8082/dbname/SampleWebService'
    TYPE 'HTTP:POST'
    HEADER 'heading1: This long value\n is really long for a header.\n 
    heading2:shortvalue';

POST 请求与下列内容类似:



POST /dbname/SampleWebService HTTP/1.0
ASA-Id: e88a416e24154682bf81694feaf03052
User-Agent: SQLAnywhere/16.0.0.1403
Accept-Charset: windows-1252, UTF-8, *
Date: Fri, 03 Feb 2012 15:26:04 GMT
heading1: This long value is really long for a header.     heading2:shortvalue
Host: localhost:8082
Connection: close
Content-Type: application/x-www-form-urlencoded; charset=windows-1252
Content-Length: 0
注意

创建 SOAP 函数或过程时,必须设置 SOAPAction HTTP 请求标头为 WSDL 中指定的给定 SOAP 服务 URI。

 自动生成 HTTP 请求标头
 另请参见