Utl_http.SET_HEADER
Hi to all ....
I have a package that use wpg_docload.download_file to show a file stored in the database
Now a customer ask to me if i can add some hader information
Somethig like in java is
resp.addHeader ('meta-doc_id','12345');
How can I do this in my package ???
can be something like
utl_http.SET_HEADER(HTTP_REQ, ('meta-docid','12345');
Am not a Java programmer and can only guess what the Java code does.
As for using wpg_docload.download_file - the sample code I posted above is exactly how one goes about creating a HTTP header to stream data using wpg_docload.download_file.
As for the special tag you needs to create. That will be done as I've shown in the example. How the actual tag looks like - that is hard to say from the code snippet you've posted that creates the tag using Java. The question is how does that actual tag looks like in the HTTP header - and not what the "equivalent" command in PL/SQL is for that Java command that creates the tag.
In other words, the requirement specification should be "+create this tag in the header and this is how it looks like+".
Not "+here's the Java statement, now duplicate it in PL/SQL+". This is not a sensible or logical requirement by any stretch of the imagination.
In your sh0es, I will insist on a proper technical specification that details how that HTTP response needs to look like. What is expected in the HTTP header? What is expected in the HTTP body/payload? Don't show me Java code as the requirement and say "duplicate this". That is not how software is designed and engineered.
Similar Messages
-
Utl_http error help required
Hi,
Thanks for help,
I create the following procedure for this purpose and i received the following errors:
declare
txt Varchar2(4000);
request utl_http.req;
response utl_http.resp;
BEGIN
utl_http.set_proxy('','');
request := utl_http.begin_request('http://localhost:7778/reports/rwservlet?report=f:\oracle\TIS13.rdf&desformat=pdf&destype=cache&userid=wh1/wh1@dwh');
--utl_http.set_header(request, 'User-Agent', 'Mozilla/4.0');
response := utl_http.get_response(request);
LOOP
utl_http.read_line(response, txt, TRUE);
dbms_output.put_line(txt);
END LOOP;
utl_http.end_response(response);
EXCEPTION
WHEN utl_http.end_of_body THEN
utl_http.end_response(response);
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
end;ERROT AT line1:
ORA-29273: HTTP request failed
ORA-06512" at "SYS.UTL_HTTP",line 1231
ORA-29276: transfer timout
ORA-06512: at line 20
Any solution would be hightly appriciated
Regardsit would be easier for you to use the OOTB Reports integration with Portal:
- http://download.oracle.com/docs/cd/B14099_19/bi.1012/b14048/pbr_portal.htm#i1008279
Cheers,
Mick -
How to send XML using UTL_HTTP
I am trying to workout how to send XML data to a webserver using UTL_HTTP but am not getting any reply
I need to submit the following XML document to a server "http://api.fastsms.co.uk/api/xmlapi.php" Their instructions are "The XML Document should be posted unencoded, with a UTF-8 character set as parameter 'xml'"
If I submit the following XML on their test form
<?xml version="1.0"?>
<apirequest version="1">
<user>
<username>**USER**</username>
<password>**PASSWORD**</password>
</user>
<application>
<name>Example Application</name>
<version>1.0</version>
</application>
<inboundcheck lastid="10711399"/>
</apirequest>
I get an XML response back with the messages in my inbox.
This is the code I am trying to use to accomplish the same from PL/SQL : I know a response is coming back as there is header information - just no content. What am I doing wrong ?
l_xml VARCHAR2(5000);
req utl_http.req;
resp utl_http.resp;
header_name VARCHAR2(256); -- Response header name
header_value VARCHAR2(1024); -- Response header value
response_text VARCHAR2(4000); -- Response body
l_url VARCHAR2(100);
BEGIN
l_xml := 'xml=<?xml version="1.0"?>';
l_xml := '<apirequest version="1">';
l_xml := '<user>';
l_xml := '<username>**USER**</username>';
l_xml := '<password>**PASSWORD**</password>';
l_xml := '</user>';
l_xml := '<application>';
l_xml := '<name>Example Application</name>';
l_xml := '<version>1.0</version>';
l_xml := '</application>';
l_xml := '<inboundcheck lastid="10711399"/>';
l_xml := '</apirequest>';
-- Open HTTP connection
l_url := 'http://api.fastsms.co.uk/api/xmlapi.php';
req := utl_http.begin_request(l_url,'POST',utl_http.HTTP_VERSION_1_1);
-- Set headers for type and length
utl_http.set_header(req,'Content-Type','application/x-www-form-urlencoded');
utl_http.set_header(req,'Content-Length',to_char(length(l_xml)));
-- Write parameter
utl_http.write_text(req,l_xml);
-- Read response file
resp := utl_http.get_response(req);
-- Print out the response headers
FOR i IN 1 .. utl_http.get_header_count(resp) LOOP
utl_http.get_header(resp,i,header_name,header_value);
logging_pkg.info(header_name || ': ' || header_value);
END LOOP;
-- Print out the response body
BEGIN
LOOP
utl_http.read_text(resp,response_text);
logging_pkg.info(response_text);
END LOOP;
EXCEPTION
WHEN utl_http.end_of_body THEN
logging_pkg.info('End of body');
END;
-- close http connection
utl_http.end_response(resp);
EXCEPTION
WHEN utl_http.end_of_body THEN
utl_http.end_response(resp);
END;
Cheers,
BrentHi Billy
Yikes - how embarassing ! Thanks for pointing out my beginners mistake there. I've fixed my code - and also implemented the substitutions of parameters like you suggested - I like that approach.
Unfortunately the end result is no better - the line
utl_http.read_text(resp,response_text);
Still returns nothing back
The headers that are coming back are
Date: Thu, 04 Jul 2013 08:31:56 GMT
Server: Apache/2.2.16 (Ubuntu)
X-Powered-By: PHP/5.3.3-1ubuntu9.3
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Connection: close
I guess I will need to try chasing it with the fastsms vendor so see if they can check my incoming request and see if there are any glaring problems. I know the xml is correct as I am now logging the xml string just before I send it and when I take that string and put it in their test form it works perfectly - something else in the puzzle is missing. I've had no experience using utl_http before - perhaps it's no possible to read the xml repsonse using this ?
Anyway, thanks for your help Billy.
ps - How do you paste your code into your message to get that formatting ?
Cheers,
Brent -
I have the following PLSQL Function that returns a End_of_body Error. This started when we migrated from 10g to 11g. It is simple enough to capture so the error does not stop the Function Flow, but the error causes the OCI driver in OBIEE to error, which prevents the use of OBIEE IBOT to execute. Trying to understand why this error is occurring..not sure if we have a permissions issue on the UTL_HTTP Package or what?
Anyone seen this problem in 11g? Suggests on resolving would be great. Thanks.
FUNCTION AA_DEMO_PO_WSDL(IN_MESSAGE IN VARCHAR2)
RETURN VARCHAR IS
soap_request varchar2(30000);
soap_respond varchar2(30000);
http_req utl_http.req;
http_resp utl_http.resp;
launch_url varchar2(240) ;
o_message varchar2(240) ;
po_amount number := 2000 ;
total_calls number := 0;
cursor c_PO_exists is Cursor Logic..
begin
total_calls := 0;
For po_wsdl in c_PO_exists
LOOP
total_calls := total_calls + 1;
soap_request:='<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body xmlns:ns1="http://xmlns.oracle.com/PurchaseOrder_Approval">
<ns1:ProcessRequest><ns1:input>PO' || po_wsdl.order_no || '</ns1:input></ns1:ProcessRequest>
</soap:Body>
</soap:Envelope>';
Begin
http_req:= utl_http.begin_request('myURL/PurchaseOrder_Approval/1.0','POST','HTTP/1.1');
utl_http.set_header(http_req, 'Content-Type', 'text/xml') ;
utl_http.set_header(http_req, 'Content-Length', length(soap_request)) ;
utl_http.set_header(http_req, 'SOAPAction', 'initiate');
utl_http.write_text(http_req, soap_request) ;
http_resp:= utl_http.get_response(http_req) ;
utl_http.read_text(http_resp, soap_respond) ;
utl_http.end_response(http_resp) ;
Exception
WHEN UTL_HTTP.end_of_body THEN
utl_http.end_response(http_resp);
When utl_http.too_many_requests then
utl_http.end_response(http_resp);
o_message := 'End_Reponse' || ' from proc.';
when OTHERS then
o_message := SQLERRM || ' from proc.';
return o_message;
end;
END LOOP;
Return 'Workflow Initiated-' ||to_char(total_calls);
end AA_DEMO_PO_WSDL;Hi, thanks,
it is oracle10g,
The Exception is : ORA-29266: end-of-body reached
ORA-06512: at "SYS.UTL_HTTP", line 1349
then the line in my function ,
damorgan wrote:
But I do note that when I do this I always do a get_header_count and get_header before get_read.what get_read , u mean?
thanks for the link ,
appreciated -
Error invoking SSL web service using pl sql UTL_HTTP
Web Services Gurus,
I am invoking a secure web service based on the following WSDL file from a pl/sql program using UTL_HTTP package.
The web service is secure and prompts for authentication.
The web services certificate is imported in Oracle Wallet on Database Server.
I am listing the WSDL file, the pl/sql code and error message as follows -
1. The WSDL file -
<definitions
name="Webservice"
targetNamespace="http://webservice.airclic.com/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://webservice.airclic.com/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
>
<types>
<xs:schema targetNamespace="http://webservice.airclic.com/" version="1.0" xmlns:tns="http://webservice.airclic.com/"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Exception" type="tns:Exception"/>
<xs:element name="sendAuthenticationResponse" type="tns:sendAuthenticationResponse"/>
<xs:element name="sendAuthenticationResponseResponse" type="tns:sendAuthenticationResponseResponse"/>
<xs:complexType name="AuthenticationResponse">
<xs:complexContent>
<xs:extension base="tns:Response">
<xs:sequence>
<xs:element name="success" type="xs:boolean"/>
<xs:element name="username" type="xs:string"/>
<xs:element minOccurs="0" name="password" type="xs:string"/>
<xs:element minOccurs="0" name="firstName" type="xs:string"/>
<xs:element minOccurs="0" name="lastName" type="xs:string"/>
<xs:element minOccurs="0" name="email" type="xs:string"/>
<xs:element minOccurs="0" name="active" type="xs:boolean"/>
<xs:element minOccurs="0" name="timeZone" type="xs:string"/>
<xs:element minOccurs="0" name="group" type="xs:string"/>
<xs:element minOccurs="0" name="role" type="xs:string"/>
<xs:element minOccurs="0" name="errorCode" type="xs:string"/>
<xs:element minOccurs="0" name="errorMessage" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="DispatchEvent"></xs:complexType>
<xs:complexType name="sendAuthenticationResponse">
<xs:sequence>
<xs:element minOccurs="0" name="authenticationResponse" type="tns:AuthenticationResponse"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sendAuthenticationResponseResponse">
<xs:sequence/>
</xs:complexType>
<xs:simpleType name="status"></xs:simpleType>
<xs:simpleType name="source"></xs:simpleType>
<xs:simpleType name="eventType"></xs:simpleType>
</xs:schema>
</types>
<message name="Webservice_sendAuthenticationResponse">
<part name="sendAuthenticationResponse" element="tns:sendAuthenticationResponse"/>
</message>
<message name="Webservice_sendAuthenticationResponseResponse">
<part name="sendAuthenticationResponseResponse" element="tns:sendAuthenticationResponseResponse"/>
</message>
<portType name="Webservice">
<operation name="sendAuthenticationResponse" parameterOrder="sendAuthenticationResponse">
<input message="tns:Webservice_sendAuthenticationResponse"/>
<output message="tns:Webservice_sendAuthenticationResponseResponse"/>
<fault name="Exception" message="tns:Exception"/>
</operation>
</portType>
<binding name="WebserviceBinding" type="tns:Webservice">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sendAuthenticationResponse">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="Exception">
<soap:fault name="Exception" use="literal"/>
</fault>
</operation>
</binding>
<service name="Webservice">
<port name="WebservicePort" binding="tns:WebserviceBinding">
<soap:address location="https://host.airclic.com:443/webservice/product/fieldservice/v1/Webservice"/>
</port>
</service>
</definitions>
2. The pl/sql code that calls the web service operation sendAuthenticationResponse
procedure send_auth_response
as
soap_request varchar2(30000);
soap_respond varchar2(30000);
http_req utl_http.req;
http_resp utl_http.resp;
resp XMLType;
i integer;
begin
-- initiate wallet for AirClic certificate
dbms_output.put_line ('1');
utl_http.set_wallet('file:/etc/oracle/wallet','<wallet password>');
-- create soap request
dbms_output.put_line ('2');
soap_request:= '<?xml version = "1.0" encoding = "UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:sendAuthenticationResponse xmlns="https://host.airclic.com:443/webservice/product/fieldservice/v1/Webservice" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<success xsi:type="xsd:boolean">true</success>
<username xsi:type="xsd:string">changlanih</username>
<password xsi:type="xsd:string">abcd1234</password>
<firstName xsi:type="xsd:string">hero</firstName>
<lastName xsi:type="xsd:string">changlani</lastName>
<email xsi:type="xsd:string">[email protected]</email>
<active xsi:type="xsd:boolean">true</active>
<timeZone xsi:type="xsd:string">eastern</timeZone>
<group xsi:type="xsd:string">Northeast</group>
<role xsi:type="xsd:string">Service Manager</role>
<errorCode xsi:type="xsd:string"></errorCode>
<errorMessage xsi:type="xsd:string"></errorMessage>
</ns1:sendAuthenticationResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>';
-- request that exceptions are raised for error Status Codes
dbms_output.put_line ('3');
utl_http.set_response_error_check (true);
-- allow testing for exceptions like UTL_HTTP.http_server_error
dbms_output.put_line ('4');
utl_http.set_detailed_excp_support (true);
--utl_http.set_transfer_timeout (ln_time_out);
dbms_output.put_line ('5');
utl_http.set_body_charset ('UTF-8');
-- begin request
dbms_output.put_line ('5.5');
http_req:= utl_http.begin_request
('https://host.airclic.com:443/webservice/product/fieldservice/v1/Webservice/sendAuthenticationResponse', ------ is the url correct here ?
'POST',
'HTTP/1.1'
dbms_output.put_line ('6');
utl_http.set_authentication(http_req, '<username for webservice>', '<password for webservice user>');
dbms_output.put_line ('7');
utl_http.set_persistent_conn_support (http_req, false);
dbms_output.put_line ('8');
utl_http.set_header(http_req, 'Content-Type', 'text/xml'); -- since we are dealing with plain text in XML documents
dbms_output.put_line ('9');
utl_http.set_header(http_req, 'Content-Length', length(soap_request));
dbms_output.put_line ('10');
utl_http.set_header(http_req, 'SOAPAction', ''); -- required to specify this is a SOAP communication
dbms_output.put_line ('11');
utl_http.write_text(http_req, soap_request);
dbms_output.put_line ('12');
http_resp := utl_http.get_response(http_req);
-- debug messages
DBMS_OUTPUT.PUT_LINE('-------utl_http.get_response---------------------');
DBMS_OUTPUT.PUT_LINE('http_resp.status_code is :'||http_resp.status_code );
DBMS_OUTPUT.PUT_LINE('http_resp.reason_phrase is :'||http_resp.reason_phrase);
DBMS_OUTPUT.PUT_LINE('http_resp.http_version is :'||http_resp.http_version);
DBMS_OUTPUT.PUT_LINE('http_resp.private_hndl is :'||http_resp.private_hndl);
DBMS_OUTPUT.PUT_LINE('-------utl_http.get_response----------------------');
utl_http.read_text(http_resp, soap_respond);
dbms_output.put_line ('13');
utl_http.end_response(http_resp);
dbms_output.put_line ('14');
resp := XMLType.createXML(soap_respond);
dbms_output.put_line ('15');
resp := resp.extract('/soap:Envelop/soap:Body/child::node()',
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"');
i:=0;
dbms_output.put_line ('16');
loop
dbms_output.put_line(substr(soap_respond, 1 + i * 255, 250));
i := i + 1;
if (i * 250) > length(soap_respond) then
exit;
end if;
end loop;
exception
when utl_http.request_failed then
dbms_output.put_line('request failed: ' || utl_http.get_detailed_sqlerrm);
when utl_http.http_server_error then
dbms_output.put_line('server error: ' || utl_http.get_detailed_sqlerrm);
when utl_http.http_client_error then
dbms_output.put_line('client error: ' || utl_http.get_detailed_sqlerrm);
when others then
dbms_output.put_line(sqlerrm);
end send_auth_response;
3. Output when I run the send_auth_response procedure
Connecting to the database cpdev.
1
2
3
4
5
5.5
ORA-12560: TNS:protocol adapter error
Process exited.
Disconnecting from the database cpdev.
Comments -
The web service operation only has input message. The input message consists of a complex type as seen in WSDL.
Questions -
1. This is my first attempt in invoking a web service from pl/sql program. Is the code in SOAP body correct as mapped to the complex type in WSDL ?
2. As seen from the dbms_out - the last message before ORA-12560 is 5.5, that means the call is erroring at following code line -
http_req:= utl_http.begin_request ------ what am I doing wrong here ?
3. The web service is SSL as seen from WSDLand needs a username/password for access - which is being performed by following code line -
utl_http.set_authentication(http_req, '<username for webservice>', '<password for webservice user>'); ------- is that correct ?
4. I am not using any proxy server - should I be using it ? When is it necessary to use proxy ?
Appreciate any help.
Thanx.Oracle is hosted by HOST A - this is where the pl/sql program resides.
The Web Service being accessed by pl/sql program is hosted by HOST B and there are 4 firewalls in between.
Oracle was not even able to establish connection to web services host.
Escalated the issue with networking folks and they resolved the connectivity problem.
Hope that helps. -
How to handle utl_http response
Hi,
I use the below code to call a https using POST method
utl_http.set_proxy(apex_application.g_proxy_server, NULL);
utl_http.set_persistent_conn_support(TRUE);
utl_http.set_transfer_timeout(300);
utl_http.set_wallet(p_wallet, p_wallet_pwd);
l_http_req := utl_http.begin_request(p_api_url, 'POST');
utl_http.set_header(l_http_req, 'Proxy-Connection', 'Keep-Alive');
utl_http.set_header(l_http_req, 'Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
utl_http.set_header(l_http_req, 'Content-Length', length(l_post));
utl_http.write_text(l_http_req, l_post);
l_http_resp := utl_http.get_response(l_http_req);
utl_http.read_text(l_http_resp, l_response);
The url return a respose with below l_response content
<html>
<head>
<META HTTP-EQUIV='content-type' CONTENT='text/html; charset=UTF8'>
</head>
<title>Payment Page</title>
<form method="POST" name="ePayment" action="http://www.testing.com">
<input type="hidden" name="MerchantCode" value="M01247"><br>
<input type="hidden" name="PaymentId" value="2"><br>
<input type="hidden" name="RefNo" value="0001"><br>
<input type="hidden" name="Amount" value="1"><br>
<input type="hidden" name="Currency" value="MYR"><br>
<input type="hidden" name="Remark" value="Testing1"><br>
<input type="hidden" name="TransId" value=""><br>
<input type="hidden" name="AuthCode" value=""><br>
<input type="hidden" name="Status" value="0"><br>
<input type="hidden" name="ErrDesc" value="Permission not allow"><br>
<input type="hidden" name="Signature" value=""><br>
</form>
<script language="JavaScript">
document.ePayment.submit();
</script>
</html>
Apparently it will redirect to http://www.testing.com,
how should my procedure handle this response so it will redirect to the url?
Thanks.
Vincent pek
Edited by: [email protected] on May 3, 2010 7:09 AM<script language="JavaScript">
document.ePayment.submit();
</script>
</html>
Apparently it will redirect to http://www.testing.com,
how should my procedure handle this response so it will redirect to the url?
Thanks.
Vincent pekYour procedure should be able to run JavaScript, which it isn't.
Therefore, I would recommend that you talk to the website administrator and discuss using a webservice. -
Using utl_http tp post a mod_plsql package which has a parameter
Hi,
I'm new to using utl_http, xml and mod_plsql.
I need to test calling a mod_plsql package which receives posted data and returns a response using utl_http.
The following works fine:
SET SERVEROUTPUT ON;
CREATE OR REPLACE PROCEDURE http_test
IS
BEGIN
HTP.p (
'<?xml version="1.0" encoding="UTF-8" ?><note><to>Fred</to><from>Smith</from><heading>Reminder</heading><body>Goodbye!</body></note>
END http_test;
CREATE OR REPLACE FUNCTION HTTP_POST
RETURN VARCHAR2
IS
req UTL_HTTP.req;
resp UTL_HTTP.resp;
v_txt VARCHAR2 (1024);
posted_data VARCHAR2 (1000)
:= '<?xml version="1.0" encoding="UTF-8" ?><note><to>Fred</to><from>Smith</from><heading>Reminder</heading><body>Hello!</body></note>';
BEGIN
wallet_is_set_here;
req :=
UTL_HTTP.begin_request (
'https://url details removed for security/http_test',
'POST',
'HTTP/1.1');
UTL_HTTP.write_text (req, posted_data);
resp := UTL_HTTP.get_response (req);
UTL_HTTP.read_text (resp, v_txt);
UTL_HTTP.end_response (resp);
RETURN v_txt;
END;
SELECT http_post FROM DUAL;
i.e. it returns the following as expected:
<?xml version="1.0" encoding="UTF-8" ?><note><to>Fred</to><from>Smith</from><heading>Reminder</heading><body>Goodbye!</body></note>
However, I want to pass a parameter to the http_test procedure so I can ultimately save the posted data to a table so I can process the contents later.
If I change the code to:
CREATE OR REPLACE PROCEDURE http_test (xmlX IN VARCHAR2)
IS
BEGIN
HTP.p (
'<?xml version="1.0" encoding="UTF-8" ?><note><to>Fred</to><from>Smith</from><heading>Reminder</heading><body>Goodbye!</body></note>
END http_test;
CREATE OR REPLACE FUNCTION HTTP_POST
RETURN VARCHAR2
IS
req UTL_HTTP.req;
resp UTL_HTTP.resp;
v_txt VARCHAR2 (1024);
posted_data VARCHAR2 (1000)
:= '<?xml version="1.0" encoding="UTF-8" ?><note><to>Fred</to><from>Smith</from><heading>Reminder</heading><body>Hello!</body></note>';
BEGIN
wallet_is_set_here;
req :=
UTL_HTTP.begin_request (
'https://url details removed for security/http_test',
'POST',
'HTTP/1.1');
UTL_HTTP.set_header (req, 'Content-Type', 'text/xml; charset=utf-8');
UTL_HTTP.set_header (req, 'Content-Length', LENGTH (posted_data));
UTL_HTTP.write_text (req, posted_data);
resp := UTL_HTTP.get_response (req);
UTL_HTTP.read_text (resp, v_txt);
UTL_HTTP.end_response (resp);
RETURN v_txt;
END;
SELECT http_post FROM DUAL;
I just get a load of html returned (some of which is below to show the kind of thing):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x
html1/DTD/xhtml1-strict.dtd">
<html dir=LTR xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache" />
</head>
<body>
Please could someone advise me what I am doing wrong or if it is not possible to post in this way using utl_http. I'm hoping it is just a question of finding the correct settings but can't find an example that matches what we need to do.
If I post in a browser using an html form to the procedure when it has a parameter, the response is displayed correctly in the browser and it can be saved to a database(code not included in the above). However, our requirement is to do this in the background as we will be receiving a post from an external customer to which we have to respond based on the contents of the posted data.
Many thanks for any help.Hi,
Do you mind updating your message and using enclose the code part between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
Please read <a href="https://forums.oracle.com/forums/thread.jspa?threadID=2174552#9360002">How do I ask a question on the forums?</a> for more details.
Regards.
Al -
Error using UTL_HTTP over HTTPS
Hello,
I am trying to simply connect to an HTTPS web site. I used this query to test the connection :
select utl_http.request('https://subdomain.maindomain.com/webservice.wsdl',null, 'file:C:\MyWalletDirectory','WalletPassword') from dual;
and I always got the following error :
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1577
ORA-29268: HTTP client error
ORA-06512: at line 1
Can anybody help me with this issue ? Is it possible to have a more meaningfull message ?
Thanks...
LIBI've written a basic PL/SQL web browser template. It looks/works as follows:
SQL> select * from TABLE( webbrowser('https://metalink.oracle.com') ) where rownum < 11;
COLUMN_VALUE
Setting browser configuration
Wallet set to file:/etc/ORACLE/WALLETS/oracle/
Proxy Server is 198.54.206.99
Proxy URL modified to include proxy user name and password
Proxy URL is http://verreyb:*****@198.54.206.99
HTTP: GET https://metalink.oracle.com
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Welcome to Oracle MetaLink</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><LINK
href="oracle.htm" rel=stylesheet>
10 rows selected.
The source code:
create or replace type TStrings is table of varchar2(4000);
create or replace function WebBrowser( url varchar2 ) return TStrings pipelined is
-- BASIC PL/SQL WEB BROWSER TEMPLATE
-- supports http, https and proxy servers
-- fixed constants
C_NO_PROXY_FOR constant varchar2(4000) := 'localhost';
C_WALLET constant varchar2(4000) := 'file:/etc/ORACLE/WALLETS/oracle/';
C_WALLET_PASS constant varchar2(4000) := '<wallet password goes here>';
-- Proxy settings that can be made arguments in the WebBrowser() call
proxyServer varchar2(20) := '198.54.206.99';
-- not all proxy servers use authentication, but many corporate proxies do, in
-- which case you need to specify your auth details here
-- (make it nulls if not applicable)
proxyUser varchar2(50) := '<proxy username goes here>';
proxyPass varchar2(50) := '<proxy password goes here>';
-- our local variables
proxyURL varchar2(4000);
request UTL_HTTP.req;
response UTL_HTTP.resp;
buffer varchar2(4000);
endLoop boolean;
begin
-- our "browser" settings
PIPE ROW( 'Setting browser configuration' );
UTL_HTTP.set_response_error_check( TRUE );
UTL_HTTP.set_detailed_excp_support( TRUE );
UTL_HTTP.set_cookie_support( TRUE );
UTL_HTTP.set_transfer_timeout( 30 );
UTL_HTTP.set_follow_redirect( 3 );
UTL_HTTP.set_persistent_conn_support( TRUE );
-- set wallet for HTTPS access
PIPE ROW( 'Wallet set to '||C_WALLET );
UTL_HTTP.set_wallet( C_WALLET, C_WALLET_PASS );
-- configure for proxy access
if proxyServer is not NULL then
PIPE ROW( 'Proxy Server is '||proxyServer );
proxyURL := 'http://'||proxyServer;
if (proxyUser is not NULL) and (proxyPass is not NULL) then
proxyURL := REPLACE( proxyURL, 'http://', 'http://'||proxyUser||':'||proxyPass||'@' );
PIPE ROW( 'Proxy URL modified to include proxy user name and password' );
end if;
PIPE ROW( 'Proxy URL is '|| REPLACE(proxyURL,proxyPass,'*****') );
UTL_HTTP.set_proxy( proxyURL, C_NO_PROXY_FOR );
end if;
PIPE ROW( 'HTTP: GET '||url );
request := UTL_HTTP.begin_request( url, 'GET', UTL_HTTP.HTTP_VERSION_1_1 );
-- set HTTP header for the GET
UTL_HTTP.set_header( request, 'User-Agent', 'Mozilla/4.0 (compatible)' );
-- get response to the GET from web server
response := UTL_HTTP.get_response( request );
-- pipe the response as rows
endLoop := false;
loop
exit when endLoop;
begin
UTL_HTTP.read_line( response, buffer, TRUE );
if (buffer is not null) and length(buffer)>0 then
PIPE ROW( buffer );
end if;
exception when UTL_HTTP.END_OF_BODY then
endLoop := true;
end;
end loop;
UTL_HTTP.end_response( response );
return;
exception when OTHERS then
PIPE ROW( SQLERRM );
end;
show errorsEdited by: Billy Verreynne on Sep 4, 2008 7:47 AM (old forum tags poorly supported by new Jive forum s/w) -
Unable to receive special characters in XML using UTL_HTTP request from Other application
Hi Team,
We are using SOAP request in Oracle Application to Pull XML data from Other application.I am using below commands before receving response but still i am unable to receive special charcters/Spanish Charcters in XML.
utl_http.set_body_charset(v_http_req, 'UTF-8');
utl_http.set_header (v_http_req, 'Content-Type', 'text/xml');
Thanks and Regards,
RaghulHello,
Just when you think that you know everything, it is slammed in your face that you don't. The .Mac member name field in the System Preferences DOES NOT take your whole e-mail address. It only takes your user name or whatever comes BEFORE the "@" symbol. There was absolutely nothing wrong with my MacBook Pro (other than ther brain dead user).
Sorry for wasting your time...
If we learn from our mistakes, then I obtained my PhD years ago,
Dr. Z. -
German Characters issue while invoking Web Services via UTL_HTTP
Dear Forum Members,
I'm trying to invoke SAP CRM Web services from Oracle PL/SQL. I have used following code which is working fine.
-- call web service using Oracle UTIL_HTTP packages
DECLARE
http_req utl_http.req;
http_resp utl_http.resp;
lv_request VARCHAR2(32767);
lc_response CLOB;
lv_buffer VARCHAR2(32000);
lv_name VARCHAR2(256);
lv_hdr_value VARCHAR2(1024);
l_xml XMLType;
BEGIN
utl_http.set_persistent_conn_support(true);
utl_http.set_transfer_timeout(600);
http_req:= utl_http.begin_request
( url => 'http://xyz3ni92.server.xyz.com:8045/sap/bc/srt/xip/sap/crm_bupa_custid_qr/011/customersbycrmid/http_binding'
, method => 'POST'
lv_request := '<?xml version="1.0" encoding="UTF-8"?>'
||'<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:glob="http://sap.com/xi/CRM/Global2">'
||'<soap:Header/>'
||'<soap:Body>'
||'<glob:CustomerCRMByIDQuery>'
||'<MessageHeader>'
||'<ID schemeID="?" schemeAgencyID="?" schemeAgencySchemeAgencyID="?"></ID>'
||'<UUID></UUID>'
||'<ReferenceID schemeID="?" schemeAgencyID="?" schemeAgencySchemeAgencyID="?"></ReferenceID>'
||'<ReferenceUUID></ReferenceUUID>'
||'</MessageHeader>'
||'<BusinessPartnerSelectionByBusinessPartner>'
||'<UUID schemeID="?" schemeAgencyID="?"></UUID>'
||'<InternalID>2200117598</InternalID>'
||'</BusinessPartnerSelectionByBusinessPartner>'
||'</glob:CustomerCRMByIDQuery>'
||'</soap:Body>'
||'</soap:Envelope>';
/*set username and password*/
utl_http.set_authentication (
r => http_req,
username => 'WS_USER',
password => 'WS_PASSWORD',
scheme => 'Basic',
for_proxy => false);
utl_http.set_header(http_req, 'Content-Type', 'application/soap+xml;charset=UTF-8');
utl_http.set_header(http_req, 'Content-Length', LENGTHB(lv_request));
utl_http.write_text(http_req, lv_request);
/*Make HTTP call*/
http_resp:= utl_http.get_response(http_req);
/*read response text from response*/
BEGIN
LOOP
utl_http.read_text(http_resp, lv_buffer);
lc_response := lc_response || TO_CLOB(lv_buffer);
END LOOP;
EXCEPTION
WHEN OTHERS THEN
-- ora-29266 end-of-body reached
IF SQLCODE <> -29266 THEN
RAISE;
END IF;
END;
utl_http.end_response(http_resp);
l_xml := XMLType(lc_response);
/*Log response for testing*/
DELETE FROM webservice_log;
INSERT INTO webservice_log (seq_id,xml_response) VALUES (sqe_Webservice_Log.NEXTVAL,l_xml);
EXCEPTION WHEN OTHERS THEN
RAISE;
END;However, if there are any German Characters in SAP, then they are being replaced by JUNK data when they come to Oracle.
If I invoke the same web-service suing tools like SOAP-UI, then German characters are coming fine. I have also traced web-service requests/responses from SAP side, and there response is showing fine. When it comes to Oracle, they are getting corrupted.
I'm sure it's something to do with character-set, but I'm not able to find-out where and what I should fix/change.
Thanks for your help in advance.
DB: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
NLS_DATABASE_PARAMETERS
PARAMETER VALUE
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET AL32UTF8
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 11.2.0.1.0 Regards,
Hari
added further details by: Hari_639 on Apr 24, 2013 6:45 PMHello Both,
Thank you.
I ran following command from SQL Plus window after connecting to DB..
SQL> @[%NLS_LANG%]
SP2-0310: unable to open file "[AMERICAN_AMERICA.WE8MSWIN1252]"And also I have checked actual data using DUMP function, it looks like data stored is wrong.
I have updated one field in SAP such that it only contains German character ä. When I query corresponding data from Oracle I got following output..
SELECT xmlresponse.Notes,
dump(xmlresponse.Notes,1010) dump_text
FROM webservice_log,
Xmltable(Xmlnamespaces
('http://www.w3.org/2003/05/soap-envelope' AS "env",
'http://sap.com/xi/CRM/Global2' AS "nm",
'urn:sap.com:proxy:DCT:/1SAI/TAS57DF0B317943DEAE3C49:702' AS "prx"
'/env:Envelope/env:Body/nm:CustomerCRMByIDResponse/BusinessPartner'
PASSING xml_response
columns
NOTES VARCHAR2(4000) PATH 'TextCollection/Text/TextContent/Text'
) XMLRESPONSE;
/* Output */
NOTES -- DUMP_TEXT
ä Typ=1 Len=4 CharacterSet=AL32UTF8: 195,131,194,164But decimal notation for German character ä is different!
SELECT DUMP('ä',1010) dump_text from dual;
/*Output*/
DUMP_TEXT
Typ=96 Len=2 CharacterSet=AL32UTF8: 195,164Regards,
Hari -
Question on utl_http.
Hi,
I am very new to UTL_HTTP package..
I am trying to call one of my webservice using this package..here is the code for this
CREATE OR REPLACE PACKAGE BODY prepaid_service AS
FUNCTION get_prepaid(transactionNumber IN VARCHAR2, transactionType IN VARCHAR2) RETURN VARCHAR2 IS
req demo_soap.request;
resp demo_soap.response;
URL VARCHAR2(200);
ACTION VARCHAR2(200);
BEGIN
req := demo_soap.new_request('n:header',
'xmlns:n="urn:examples:prepaid"');
demo_soap.add_parameter(req, 'transactionNumber', 'xsd:string', transactionNumber);
demo_soap.add_parameter(req, 'type', 'xsd:string', transactionType);
URL := 'http://10.72.149.179:8080/soap/servlet/rpcrouter';
ACTION := NULL;
resp := demo_soap.invoke(req,URL,ACTION);
RETURN demo_soap.get_return_value(resp, 'return','xmlns:ns1="urn:examples:prepaid"');
END;
BEGIN
* Since the Web service resides outside of the firewall, we need to set
* the proxy in the current session before invoking the service.
utl_http.set_proxy('www-proxy', NULL);
utl_http.set_persistent_conn_support(TRUE);
END;
The exception handling illustrates the use of "pragma-ed" exceptions
like Utl_Http.Http_Client_Error. In a realistic example, the program
would use these when it coded explicit recovery actions.
Request_Failed is raised for all exceptions after calling
Utl_Http.Set_Detailed_Excp_Support ( enable=>false )
And it is NEVER raised after calling with enable=>true
CREATE OR REPLACE PACKAGE BODY demo_soap AS
FUNCTION new_request(method IN VARCHAR2,
namespace IN VARCHAR2)
RETURN request AS
req request;
BEGIN
req.method := method;
req.namespace := namespace;
RETURN req;
END;
PROCEDURE add_parameter(req IN OUT NOCOPY request,
name IN VARCHAR2,
reqtype IN VARCHAR2,
value IN VARCHAR2) AS
BEGIN
req.reqbody := req.reqbody ||'<'||name||' xsi:type="'||reqtype||'">'||value||'</'||name||'>';
END;
PROCEDURE generate_envelope(req IN OUT NOCOPY request,
env IN OUT NOCOPY VARCHAR2) AS
BEGIN
env := '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body><'||req.method||' '||req.namespace||'>'||req.reqbody||'</'||req.method||'></soap:Body></soap:Envelope>';
END;
PROCEDURE show_envelope(env IN VARCHAR2) AS
i pls_integer;
len pls_integer;
BEGIN
i := 1; len := length(env);
WHILE (i <= len) LOOP
dbms_output.put_line(substr(env, i, 60));
i := i + 60;
END LOOP;
END;
PROCEDURE check_fault(resp IN OUT NOCOPY response) AS
fault_node xmltype;
fault_code VARCHAR2(256);
fault_string VARCHAR2(32767);
BEGIN
fault_node := resp.doc.extract('/soap:Fault','xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/');
IF (fault_node IS NOT NULL) THEN
fault_code := fault_node.extract('/soap:Fault/faultcode/child::text()', 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/').getstringval();
fault_string := fault_node.extract('/soap:Fault/faultstring/child::text()', 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/').getstringval();
raise_application_error(-20000, fault_code || ' - ' || fault_string);
END IF;
END;
FUNCTION invoke(req IN OUT NOCOPY request,
url IN VARCHAR2,
action IN VARCHAR2) RETURN response AS
env VARCHAR2(32767);
http_req utl_http.req;
http_resp utl_http.resp;
resp response;
BEGIN
generate_envelope(req, env);
show_envelope('url='||url);
show_envelope('action='||action);
show_envelope(env);
-- show_envelope(env);
http_req := utl_http.begin_request(url,'POST','HTTP/1.0');
utl_http.set_header(http_req, 'Content-Type', 'text/xml');
utl_http.set_header(http_req, 'Content-Length', length(env));
utl_http.set_header(http_req, 'SOAPAction', action);
utl_http.write_text(http_req, env);
http_resp := utl_http.get_response(http_req);
utl_http.read_text(http_resp, env);
utl_http.end_response(http_resp);
resp.doc := xmltype.createxml(env);
resp.doc := resp.doc.extract('/soap:Envelope/soap:Body/child::node()',
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"');
show_envelope(resp.doc.getstringval());
check_fault(resp);
RETURN resp;
--RETURN NULL;
END;
FUNCTION invoke11 RETURN response AS
req demo_soap.request;
env VARCHAR2(32767);
http_req utl_http.req;
http_resp utl_http.resp;
resp response;
URL VARCHAR2(200);
ACTION VARCHAR2(200);
BEGIN
dbms_output.put_line('IN invoke11');
req := demo_soap.new_request('n:header',
'xmlns:n="urn:examples:prepaid"');
demo_soap.add_parameter(req, 'transactionNumber', 'xsd:string','1234');
demo_soap.add_parameter(req, 'type', 'xsd:string', 'transactionType');
URL := 'http://10.72.149.179:8080/soap/servlet/rpcrouter';
ACTION := NULL;
generate_envelope(req, env);
dbms_output.put_line('gen env');
show_envelope('url='||url);
show_envelope('action='||action);
show_envelope(env);
-- show_envelope(env);
http_req := utl_http.begin_request(url,'POST','HTTP/1.0');
dbms_output.put_line('after B req');
utl_http.set_header(http_req, 'Content-Type', 'text/xml');
utl_http.set_header(http_req, 'Content-Length', length(env));
utl_http.set_header(http_req, 'SOAPAction', action);
dbms_output.put_line('start write');
utl_http.write_text(http_req, env);
dbms_output.put_line('end write');
http_resp := utl_http.get_response(http_req);
dbms_output.put_line('end resp');
utl_http.read_text(http_resp, env);
utl_http.end_response(http_resp);
resp.doc := xmltype.createxml(env);
resp.doc := resp.doc.extract('/soap:Envelope/soap:Body/child::node()',
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"');
show_envelope(resp.doc.getstringval());
check_fault(resp);
RETURN resp;
--RETURN NULL;
END;
FUNCTION get_return_value(resp IN OUT NOCOPY response,
name IN VARCHAR2,
namespace IN VARCHAR2) RETURN VARCHAR2 AS
BEGIN
RETURN resp.doc.extract('//'||name||'/child::text()',namespace).getstringval();
END;
END;
when i called first procedure(get_prepaid), it is not working it is giving error as "ORA-12545: Connect failed because target host or object does not exist
ORA-06512: at "SYS.UTL_HTTP", line 1020
ORA-06512: at "RMS_BATCH.PREPAID_SERVICE", line 36
ORA-06512: at line 10"
But when i try run demo_soap.invoke11(), it is giving me proper output.. Couldn't find out why this error is coming..I am trying to run invoke11() from TOAD.
Please help me in resolving this problem..
Thanks in advance
Satya/apps
bkrdlr@tsrdclvmappq# ls -ld /apps/bkrdlr/interface_files/
drwxrwsr-x 3 oraqabdc mqm 4096 Mar 29 16:51 /apps/bkrdlr/interface_files/
/apps
bkrdlr@tsrdclvmappq# ls -ld /apps/bkrdlr
drwxrwxr-x 12 bkrdlr mqm 4096 Mar 30 09:34 /apps/bkrdlr
/apps
bkrdlr@tsrdclvmappq# ls -ld /apps
drwxr-xr-x 7 root root 4096 Jul 27 2010 /apps
/apps
bkrdlr@tsrdclvmappq# sqlplus cms/cms
SQL*Plus: Release 11.1.0.7.0 - Production on Wed Mar 30 17:20:15 2011
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for IBM/AIX RISC System/6000: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
SQL>Thank you. -
Exception when working with UTL_HTTP.read_text
Hi,
I have written a block of code to read XML from a URL and then I write it to a file, using UTL_HTTP package.
The code has been working fine for two months and all of a sudden, I get the following error while reading from one of the URLs:
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line
1327
ORA-06502: PL/SQL: numeric or value error
The piece of code is pasted below for your reference.
http_req := utl_http.begin_request('my_url','GET','HTTP/1.1');
utl_http.set_body_charset(http_req, 'UTF-8');
utl_http.set_header(http_req, 'Content-Type', 'text/xml');
http_resp:= utl_http.get_response(http_req);
LOOP
UTL_HTTP.read_text(http_resp, l_text, 32767);
UTL_FILE.PUT_LINE(file_handle, l_text);
END LOOP;However, when I reduce the number of characters to be read in UTL_HTTP.read_text to 30000, it works. FYI, it isn't working with 32000 as well, while it worked perfect with 32767 all this while. This exception came up today.
I understand this has something to do with the data being read, however, my question is:
1. If I specify that 32767 characters are to be read, why should there be a buffer problem? (I am executing the same procedure for 10 other URLs and they are working fine. Its just one URL which has given a problem today)
2. What is a good solution to implement? If i reduce the number to 30000 to solve the problem today, and it gives the same problem the next time, reducing the number further doesn't look like a permanent solution.
Appreciate your help on this. Please let me know if I need to furnish any more details on this.Roger,
I have another question here. I declare the text into which I am reading my response chunk as:
l_text VARCHAR2(32767 char);rather than plainly declaring it as:
l_text VARCHAR2(32767);the second method defaults it to 32767 bytes, but isn't the first way taking it as 32767 character values?
Even now I get the same exception. Any clue here? -
Using UTL_HTTP.GET_RESPONSE function (PL/SQL)
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?
ThanksHello !
I have not understand exactly what have you try to achieve with your code , but i thing there are few things misunderstood in your code ,
so i'm posting this very basic but working example in hope that it will help you
SQL>
SQL>
SQL> conn scott/tiger
Connected.
SQL>
SQL>
SQL> create or replace procedure http_test is
2 begin
3 htp.p('<PROVA>test</PROVA>');
4 end http_test;
5 /
Procedure created.
SQL> CREATE OR REPLACE function HTTP_POST return varchar2 is
2
3 req utl_http.req;
4 resp utl_http.resp;
5
6 v_txt varchar2(1024);
7
8 BEGIN
9
10 req := UTL_HTTP.begin_request ('http://localhost:7777/pls/my_utf8/http_test'
11 ,'POST','HTTP/1.1');
12 Utl_Http.Set_Authentication ( r => req, username => 'scott', password => 'tiger'
13 , scheme => 'Basic', for_proxy => false );
14 resp := UTL_HTTP.get_response (req);
15 utl_http.read_text(resp,v_txt);
16 utl_http.end_response(resp);
17 return v_txt;
18 END;
19 /
Function created.
SQL> select http_post from dual;
HTTP_POST
<PROVA>test</PROVA>
SQL> T -
Dear All,
We are calling Web services using UTL_http through one of our custom package in Oracle 10.2.0.5 .. & it is giving correct result/output..
But if we are calling web services using the same custom package from oracle 11.2.0.2 & it is giving us error..
utl http handling in custom package as :
soap_request :=
'<?xml version = "1.0" encoding = "UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Body>'
|| v_request_xml -- input xml that we are sending
|| '</SOAP-ENV:Body></SOAP-ENV:Envelope>';
http_req :=
UTL_HTTP.begin_request (fx_service_url, -- fx_service_url is URL web service which are calling
'POST',
'HTTP/1.1'
UTL_HTTP.set_header (http_req,
'Content-Type',
'text/xml'
UTL_HTTP.set_header (http_req,
'Content-Length',
LENGTH (soap_request)
UTL_HTTP.set_header (http_req, 'SOAPAction', '');
UTL_HTTP.write_text (http_req, soap_request);
http_resp := UTL_HTTP.get_response (http_req);
DBMS_OUTPUT.PUT_LINE('HTTP response status code: ' || http_resp.status_code);
DBMS_OUTPUT.PUT_LINE('HTTP response reason phrase: ' || http_resp.reason_phrase);
UTL_HTTP.read_text (http_resp, soap_respond);
UTL_HTTP.end_response (http_resp);
Output in 10g :
HTTP response status code: 200
HTTP response reason phrase: OK
Output in 11g :
HTTP response status code: 400
HTTP response reason phrase: Bad Request
Query :
1. is there any difference of handling utl_http in oracle 10.2.0.5 to 11.2.0.2 ?
2. we recently upgraded oracle database from 10.2.0.5 to 11.2.0.2.. is/are there any setting which we need to take care while passing xml from oracle database to web service ..?
3. do we need to change any setting in we-services server also in case database upgraded from ..?
Thanks,For SQL Developer, see my advices in Re: Oracle 10g - Chinese Charecter issue and Re: insert unicode data into nvarchar2 column in a non-unicode DB
-- Sergiusz -
Invalid request when calling REST-webservice with UTL_HTTP.
Hello,
When i try to send some data to a REST-webservice i get as response "INVALID REQUEST"
I Think it is about the request-body that seems to be no UTF-8.
I tried to set the characterset with utl_http.set_body_charset(t_http_req, 'UTF-8').
But when i read the characterset with utl_http.get_body_charset(t_charset);, is still get "ISO-8859-1"
I am using: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
Some help would realy be appreciated because i am out of options trying to get the code working..
======MY CODE==========
create or replace procedure ipm40_send_bekendmaking(p_bdmg_id in number)
as
r_bekendmaking ipm40_bekendmakingen%rowtype;
r_gemeente ipm40_gemeenten%rowtype;
l_url httpuritype;
t_http_req utl_http.req;
t_http_resp utl_http.resp;
t_request_body varchar2(32767);
t_respond varchar2(32767);
-- t_teller integer := 1;
-- t_output varchar2(2000);
t_start number := 1;
t_body_lengte number;
t_chunkdata varchar2(4000);
t_tijd_1 varchar2(256);
t_tijd_2 varchar2(256);
t_timeout integer;
t_length number;
t_charset varchar2(256);
begin
select *
into r_bekendmaking
from ipm40_bekendmakingen
where id = p_bdmg_id;
select *
into r_gemeente
from ipm40_gemeenten
where gmte_code = r_bekendmaking.gmte_code;
l_url := httpuritype.createuri('http://zwolle.stadsbeheer.com:82/apex/ipm40bekendmaking?p_bdmg_id='||r_bekendmaking.id);
t_request_body := l_url.getClob();
/* request that exceptions are raised for error Status Codes */
--Utl_Http.Set_Response_Error_Check ( enable => true );
/* allow testing for exceptions like Utl_Http.Http_Server_Error */
--Utl_Http.Set_Detailed_Excp_Support ( enable => true );
utl_http.set_transfer_timeout(300);
t_http_req:= utl_http.begin_request( r_gemeente.url_webservice_bekendmakingen
, 'POST'
, 'HTTP/1.1');
utl_http.set_body_charset(t_http_req, 'UTF-8');
utl_http.get_body_charset(t_charset);
utl_http.set_authentication(t_http_req,r_gemeente.user_webservice_bekendmakingen,r_gemeente.pw_webservice_bekendmakingen);
t_length := length(t_request_body);
utl_http.set_header(t_http_req, 'Content-Type', 'application/xml charset=UTF-8');
utl_http.set_header(t_http_req, 'Content-Length', t_length);
utl_http.set_header(t_http_req, 'Transfer-Encoding', 'chunked' ); --
t_body_lengte := dbms_lob.getlength(t_request_body);
loop
t_chunkdata := dbms_lob.substr(t_request_body, 2000, t_start);
utl_http.write_text ( t_http_req, t_chunkdata );
t_start := t_start + 2000;
if t_start > t_body_lengte
then
exit;
end if;
end loop;
t_http_resp:= utl_http.get_response(t_http_req);
utl_http.read_text(t_http_resp, t_respond);
utl_http.end_response(t_http_resp);
if instr(t_respond,'Successfully document processed') != 0
then
update ipm40_bekendmakingen
set ind_status = 'S'
, datum_verzonden = sysdate
, response = t_respond
where id = r_bekendmaking.id;
else
update ipm40_bekendmakingen
set ind_status = 'F'
, datum_verzonden = null
, response = t_respond
where id = r_bekendmaking.id ;
end if;
commit;
exception
when others
then
t_tijd_2 := to_char(sysdate,'HH24:MI:SS');
t_respond := substr(sqlerrm,1,2000);
update ipm40_bekendmakingen
set ind_status = 'F'
, datum_verzonden = null
, response = t_respond
where id = r_bekendmaking.id ;
commit;
end;
===THE RESPOND=============
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The requested URL could not be retrieved</TITLE>
<STYLE type="text/css"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE>
</HEAD><BODY>
<H1>ERROR</H1>
<H2>The requested URL could not be retrieved</H2>
<HR noshade size="1px">
<P>
While trying to process the request:
<PRE>
POST /pushxml/pushxml-bm HTTP/1.0
Authorization: Basic Ymtfc21hcnRob2xkaW5nOllyZXMzdlFR
Content-Type: application/xml charset=UTF-8
Content-Length: 2096
Transfer-Encoding: chunked
Connection: close
</PRE>
<P>
The following error was encountered:
<UL>
<LI>
<STRONG>
Invalid Request
</STRONG>
</UL>
<P>
Some aspect of the HTTP Request is invalid. Possible problems:
<UL>
<LI>Missing or unknown request method
<LI>Missing URL
<LI>Missing HTTP Identifier (HTTP/1.0)
<LI>Request is too large
<LI>Content-Length missing for POST or PUT requests
<LI>Illegal character in hostname; underscores are not allowed
</UL>
<P>Your cache administrator is [email protected].
<BR clear="all">
<HR noshade size="1px">
<ADDRESS>
Generated Fri, 12 Aug 2011 17:33:24 GMT by asd2cc001.asp4all.nl (squid)
</ADDRESS>
</BODY></HTML>Always check the access_log and error_log files of the Apache web server in such a case. This will identify whether the error comes from Apache itself, mod_plsql, the Apex run-time engine, or the Oracle database.
I see that you're creating a HTTP/1.1 in PL/SQL - however, the web server response indicates a HTTP/1.0 call was received. Unusual. And could be part of the problem.
Maybe you are looking for
-
Hi, While droping a scheduler i'm getting error message like this. What i have do to? begin dbms_scheduler.drop_job('123',false); end; begin ERROR at line 1: ORA-00931: missing identifier ORA-06512: at "SYS.DBMS_UTILITY", line 132 ORA-06512: at "SYS.
-
Hello, I'm using RPAD function in stored procedure 4 times in one query and then inserting to another table. from dm_exec_sql_text table I see that every time that procedure approach to Rpad function it's open and closing in the and so it's open and
-
Thunderbolt ethernet en3 interface not appearing on MacBook Pro Retina
2012 retina MBP, with a Thunderbolt ethernet adapter. Fully up to date, including this week's Thunderbolt firmware update. Plug the Thunderbolt ethernet adapter into any port -- the kernel sort of sees it, but nothing ever provides a network interf
-
How to make a field editable again after displaying error msg (validation)
Dear All, In dialog programming, I have written a validation on a text field that it should not be left blank by the user, but after displaying the message the field becomes gray (non-editable). How can I make it editable once again after displaying
-
Hi, I am S&D consultant when ever i am doing some changes & saving, it ts not getting saved .Getting error like Express document "Update was terminated" received from author "XXX" . Can any body help me in this. Regards, pavan.