2016-08-01 12 views
0

oracleデータベースからWebサービスからデータを取得したい。 しかし、私はそれを探しています残念ながら私は何もできません。 いくつかのヒントを教えてください.pl/sqlコードでユーザー名とパスワードでアクセスしたいです。 どうすればいいですか? はOracle PL/SQLから快適なWeb​​サービスでデータを取得

+1

私はこれを自分自身を使用しますが、[ネイティブのOracle XML DB Webサービス](https://docs.oracle.com/database/121/ADXDB/xdb_web_services.htm)の読み取りを持っていないと、[オラクルベース:WebサービスとOracle Database](https://oracle-base.com/articles/misc/web-services-and-the-oracle-database)を参照してください。 –

答えて

1

あなたは、私がcode.Iを次のようにそれを解決UTL_HTTP package

+0

あなたのアドバイスをありがとうございます。しかし、そこにはたくさんのコードがあります。非常に複雑です –

0

に見たいと思うかもしれませんが、それは便利になると思う..あなたに感謝します。

declare 
    t_http_req  utl_http.req; 
    t_http_resp utl_http.resp; 
    t_request_body varchar2(30000); 
    t_respond  varchar2(30000); 
    t_start_pos integer := 1; 
    t_output  varchar2(2000); 

begin 
    /*Construct the information you want to send to the webservice. 
    Normally this would be in a xml structure. But for a REST- 
    webservice this is not mandatory. The webservice i needed to 
    call excepts plain test.*/ 
    t_request_body := 'the data you want to send to the webservice'; 

    /*Telling Oracle where the webservice can be found, what kind of request is made 
    and the version of the HTTP*/ 
    t_http_req:= utl_http.begin_request('http://urlofwebservice' 
            , 'GET' 
            , 'HTTP/1.1'); 

    /*In my case the webservice used authentication with a username an password 
    that was provided to me. You can skip this line if it's a public webservice.*/ 
    utl_http.set_authentication(t_http_req,'username','password');          

    /*Describe in the request-header what kind of data is send*/ 
    utl_http.set_header(t_http_req, 'Content-Type', 'text/xml charset=UTF-8'); 

    /*Describe in the request-header the lengt of the data*/ 
    utl_http.set_header(t_http_req, 'Content-Length', length(t_request_body)); 

    /*Put the data in de body of the request*/ 
    utl_http.write_text(t_http_req, t_request_body); 


    /*make the actual request to the webservice en catch the responce in a 
    variable*/ 
    t_http_resp:= utl_http.get_response(t_http_req); 

    /*Read the body of the response, so you can find out if the information was 
    received ok by the webservice. 
    Go to the documentation of the webservice for what kind of responce you 
    should expect. In my case it was: 
    <responce> 
    <status>ok</status> 
    </responce> 
    */ 
    utl_http.read_text(t_http_resp, t_respond); 


     dbms_output.put_line(t_respond); 


    /*Some closing?1 Releasing some memory, i think....*/ 
    utl_http.end_response(t_http_resp); 
end; 
関連する問題