Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using UTL_HTTP.GET_RESPONSE function (PL/SQL)

f.373178iaMar 10 2010 — edited Mar 11 2010
Hello,
I have a problem using the UTL_HTTP.GET_RESPONSE (URL, 'POST') function while I try to call a function that returns an XML;

The function returning my XML is:
FUNCTION MyFunction return XMLTYPE is
begin
return XMLTYPE('<PROVA>test</PROVA>');
end MyFunction;

To perform the http call I use this function:
FUNCTION POST(URL VARCHAR2, DATA_IN CLOB) RETURN CLOB IS
BEGIN
DECLARE
DATA_OUT CLOB;
PIECE VARCHAR2(4000);
AMT PLS_INTEGER := 4000;
POS PLS_INTEGER := 1;
HTTP_REQ UTL_HTTP.REQ;
HTTP_RESP UTL_HTTP.RESP;

BEGIN
HTTP_REQ := UTL_HTTP.BEGIN_REQUEST (URL, 'POST');
UTL_HTTP.SET_HEADER(HTTP_REQ, 'content-length', LENGTH(DATA_IN));

LOOP
DBMS_LOB.READ(DATA_IN,AMT,POS,PIECE);
UTL_HTTP.WRITE_TEXT(HTTP_REQ, PIECE);
EXIT WHEN AMT < 4000;
POS := POS + AMT;
AMT := 4000;
END LOOP;

HTTP_RESP := UTL_HTTP.GET_RESPONSE (HTTP_REQ);

BEGIN

LOOP
UTL_HTTP.READ_TEXT(HTTP_RESP, PIECE);
DATA_OUT := DATA_OUT || PIECE;
END LOOP;

EXCEPTION WHEN UTL_HTTP.END_OF_BODY THEN NULL;

END;

UTL_HTTP.END_RESPONSE (HTTP_RESP);
RETURN DATA_OUT;

END;
END;


The script pl/sql that calls the preceding function is:
declare
v_resp CLOB;
v_url VARCHAR2(4000);
begin
v_url := 'http:// ... /meters.export_table.MyFunction'
v_resp := POST(v_url, '-');

end;

After this call to my url, the variabile v_resp contains the following error message:
"<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>400 Bad Request</TITLE>
</HEAD><BODY>
<H1>Bad Request</H1>
Your browser sent a request that this server could not understand.<P>
mod_plsql: /pls/prjsi/meters.export_table.MyFunction HTTP-400 Missing '=' in query string or post form<P>
<HR>
<ADDRESS>Oracle-Application-Server-10g/10.1.2.0.2 Oracle-HTTP-Server Server at websvil.aem.torino.it Port 80</ADDRESS>
</BODY></HTML>"

Do you know how I can get my XML? What is the problem in that call http for my function?

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 8 2010
Added on Mar 10 2010
2 comments
7,948 views