ITPub博客

首页 > 数据库 > Oracle > Invoking Webservice from PL/SQL Sample Code

Invoking Webservice from PL/SQL Sample Code

原创 Oracle 作者:pan_tian 时间:2014-07-03 12:22:35 0 删除 编辑

使用UTL_HTTP Package来调用Webservice的样例代码。

Sample Code:

DECLARE
  L_PARAM_LIST VARCHAR2(512);

  L_HTTP_REQUEST  UTL_HTTP.REQ;
  L_HTTP_RESPONSE UTL_HTTP.RESP;

  L_RESPONSE_TEXT VARCHAR2(32767);
BEGIN

  -- service\'s input parameters
  L_PARAM_LIST := \'FromCurrency=EUR&ToCurrency=USD\';

  -- preparing Request...
  L_HTTP_REQUEST := UTL_HTTP.BEGIN_REQUEST(\'http://www.webservicex.net/currencyconvertor.asmx/ConversionRate\',
                                           \'POST\',
                                           \'HTTP/1.1\');

  -- ...set header\'s attributes
  UTL_HTTP.SET_HEADER(L_HTTP_REQUEST,
                      \'Content-Type\',
                      \'application/x-www-form-urlencoded\');
  UTL_HTTP.SET_HEADER(L_HTTP_REQUEST,
                      \'Content-Length\',
                      LENGTH(L_PARAM_LIST));

  -- ...set input parameters
  UTL_HTTP.WRITE_TEXT(L_HTTP_REQUEST, L_PARAM_LIST);

  -- get Response and obtain received value
  L_HTTP_RESPONSE := UTL_HTTP.GET_RESPONSE(L_HTTP_REQUEST);

  UTL_HTTP.READ_TEXT(L_HTTP_RESPONSE, L_RESPONSE_TEXT);

  DBMS_OUTPUT.PUT_LINE(L_RESPONSE_TEXT);

  -- finalizing
  UTL_HTTP.END_RESPONSE(L_HTTP_RESPONSE);

EXCEPTION
  WHEN UTL_HTTP.END_OF_BODY THEN
    UTL_HTTP.END_RESPONSE(L_HTTP_RESPONSE);
END;

UTL_HTTP Package

Makes Hypertext Transfer Protocol (HTTP) callouts from SQL and PL/SQL. Can be used to access data on the Internet over the HTTP protocol.

The UTL_HTTP package provides access to the HTTP protocol. The interfaces must be called in the order shown in below Figure or an exception will be raised.





参考:http://psoug.org/reference/utl_http.html

<!-- Baidu Button BEGIN -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26687597/viewspace-1207647/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: XML Display Error in Oracle EBS: The XML page cannot be displayed
下一篇: Inventory Analyzer
请登录后发表评论 登录
全部评论
暂无介绍

注册时间:2012-02-18

最新文章