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

SQL Anywhere 12.0.1 » SQL Anywhere 服务器 - 编程 » HTTP Web 服务 » HTTP Web 服务示例 » 教程:在 RAW 服务中使用 MIME 类型

 

第 3 课:发送 RAW 请求和接收 RAW 响应

在本课中,将调用在上一课中创建的包装过程,它会向第一课中创建的 Web 服务器发送请求。有关本课所述的设置 Web 客户端以发送请求的详细信息,请参见第 2 课:设置用于发送 RAW 请求和接收 RAW 响应的 Web 客户端

注意

本课中包含对 localhost 的引用。如果 Web 客户端与 Web 服务器运行在不同的计算机上,则使用第 1 课中 Web 服务器的 IP 地址而不是 localhost

 ♦ 发送请求
  1. 如果在第二课中没有打开客户端数据库,则在 Interactive SQL 中连接它。

    dbisql -c "UID=DBA;PWD=sql;SERVER=echo_client"
  2. 调用该包装过程以发送请求并获得响应。

    在 Interactive SQL 中执行以下 SQL 语句:

    CALL setMIME('<hello>this is xml</hello>', 
        'text/xml', 
        'http://localhost:8082/EchoService'
    );

    http://localhost:8082/EchoService 变量表示数据库服务器运行在 localhost 上并监听 8082 端口。所需的 SOAP Web 服务名为 EchoService

以下结果集显示在 Interactive SQL 中:

Attribute Value
Status HTTP/1.1 200 OK
Body <hello>this is xml</hello>
Date Thu, 04 Feb 2010 13:37:23 GMT
Connection close
Expires Thu, 04 Feb 2010 13:37:23 GMT
Content-Type text/plain; charset=windows-1252
Server SQLAnywhere/12.0.1.1234

以下是发送到 Web 服务器的 HTTP 包的代表示例:



POST /EchoService HTTP/1.0
Date: Thu, 04 Feb 2010 13:37:23 GMT
Host: localhost
Accept-Charset: windows-1252, UTF-8, *
User-Agent: SQLAnywhere/12.0.1.1234
Content-Type: text/xml; charset=windows-1252
Content-Length: 49
ASA-Id: 1055532613:echo_client:echo:968000
Connection: close

valueAsXML=<hello>this is xml</hello>

以下是来自 Web 服务器的响应:

HTTP/1.1 200 OK
Server: SQLAnywhere/12.0.1.1234
Date: Thu, 04 Feb 2010 13:37:23 GMT
Expires: Thu, 04 Feb 2010 13:37:23 GMT
Content-Type: text/plain; charset=windows-1252
Connection: close

<hello>this is xml</hello>