使用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://blog.itpub.net/26687597/viewspace-1207647/