Skip to Main Content

PL/SQL using UTL_HTTP to call a method other than POST, PUT or GET.

PK_UpNorthJun 23 2014 — edited Jun 24 2014

The UTL_HTTP.BEGIN_REQUEST function has the following parameters:

UTL_HTTP.BEGIN_REQUEST (

url                           IN VARCHAR2,

method                   IN VARCHAR2 DEFAULT 'GET',

http_version           IN VARCHAR2 DEFAULT NULL,

request_context      IN request_context_key DEFAULT NULL)

RETURN req;

I have an XML file:                               DataFile.XML

I have a web service:                     http://devweb/XferLocation/Xfer.asmx

I have a web service method:          SaveDocument

The method has 2 parameters:      filepath and filename

I want to us the UTL_HTTP.BEGIN_REQUEST function to call the SaveDocument method in order to transfer the XML File to the location specified in the filepath parameter in the SaveDocument method.  Is this possible?  I have the following code, but when I run it I get the following response:

DECLARE

*

ERROR at line 1:

ORA-29273: HTTP request failed

ORA-06512: at "SYS.UTL_HTTP", line 1130

ORA-06502: PL/SQL: numeric or value error

ORA-06512: at line 28

DECLARE

  Resp_v      UTL_HTTP.RESP;

  Req_v       UTL_HTTP.REQ;

  ReadResp    CLOB;

  URL_v       VARCHAR2(500);

  FExist      BOOLEAN;

  FLen        NUMBER;

  FName_v     VARCHAR2(500);

  FName_full   VARCHAR2(500);

  Method_v    VARCHAR2(500);

  Dir_v       VARCHAR2(500);

  FPath_v     VARCHAR2(500);

  BSize       BINARY_INTEGER;

  Buffer_v    VARCHAR2(32767);

  EndOFile    BOOLEAN;

BEGIN

  Dir_v       := 'DIR_PLSQL';

  FName_v     := 'DataFile';

  FName_full  := 'DataFile.XML';

  URL_v       := 'http://devweb/XferLocation/Xfer.asmx';

  FPath_v     := '\\WebServer\Files\dev\utlfile\plsql\';

  Method_v    := 'SaveDocument(FPath_v,FName_full)';

  UTL_FILE.FGETATTR(Dir_v, FName_full, FExist, FLen, BSize);

  IF FExist THEN

    DBMS_OUTPUT.PUT_LINE('File Name: '||FName_full||CHR(10)||'File Size: '||FLen||CHR(10)||'Block Size: '||BSize);

    DBMS_OUTPUT.PUT_LINE('Method: '||Method_v);

    Req_v := UTL_HTTP.BEGIN_REQUEST(url => URL_v, method => Method_v);

    UTL_HTTP.SET_HEADER(Req_v, 'Content-Type', 'text/xml; charset=utf-8');

    UTL_HTTP.SET_HEADER(Req_v, 'Content-Length', FLen);

    UTL_HTTP.WRITE_TEXT(Req_v, Dir_v||FName_full);

    Resp_v := UTL_HTTP.GET_RESPONSE(Req_v);

    EndOFile := FALSE;

    LOOP

      EXIT WHEN EndOFile;

      BEGIN

        UTL_HTTP.READ_LINE(Resp_v, Buffer_v);

        IF LENGTH(Buffer_v) > 0 THEN

          DBMS_LOB.WRITEAPPEND(ReadResp, LENGTH(Buffer_v), Buffer_v);

        END IF;

        EXCEPTION WHEN UTL_HTTP.END_OF_BODY THEN

          EndOFile := TRUE;

      END;

    END LOOP;

    UTL_HTTP.END_RESPONSE(Resp_v);

    DBMS_OUTPUT.PUT_LINE(ReadResp);

    UTL_FILE.FRENAME(Dir_v, FName_v||'.XML', Dir_v, FName_v||'.OLD');

  END IF;

END;

/

Thank you in advance,

Paul

This post has been answered by thomaso on Jun 23 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked due to inactivity on Jul 22 2014
Added on Jun 23 2014
2 comments
1,556 views