Pass XML string to web service using UTL_HTTP

303 views
Skip to first unread message

Ninja Li

unread,
Jul 9, 2013, 2:15:10 AM7/9/13
to oracle...@googlegroups.com
Hi,
 
I am trying to call a web service within my company by using PL/SQL script. I was required to pass two parameters to the web service: a job name and a long XML string of sales data.
 
The following is the PL/SQL script I created which attempt to use post data to the web service.
 
/**************************************************/
 
DECLARE
   req   utl_http.req;
   resp  utl_http.resp;
   value  VARCHAR2(1024);
 
   p_in_job_name    VARCHAR2(20)   := 'job_name';
   p_in_sales_data  VARCHAR2(4000) := '<US_SALES><US_NORTHEST><INVOICE_DATE>07/22/2013</INVOICE_DATE>.....</US_NORTHEST></US_SALES>';  
 
   v_url VARCHAR2(4000) := 'http://myurl/MyService.asmx?'   
                           || 'jobName='                                           
                           || p_in_job_name                                       
                           || '\&salesData='                                             
                           || p_in_sales_data;

BEGIN
   req := utl_http.begin_request(v_url);
  
   utl_http.set_header(req,'User-Agent','Mozilla/4.0');
  
   resp := utl_http.get_response(req);
   LOOP
     utl_http.read_line(resp, value, TRUE);
     
     dbms_output.put_line(value);
   END LOOP;
   utl_http.end_response(resp);
EXCEPTION
   WHEN utl_http.end_of_body
   THEN
      utl_http.end_response(resp);
END;
/
 
/**************************************************/
 
Where I run it in Oracle 11g v2, I received the following error message:
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request</h2>
<hr><p>HTTP Error 400. The request is badly formed.</p>
</BODY></HTML>
 
I know the same kind of script works on another web service in the company that don't have XML string as input parameters. The web service to be called also works as well.
 
I suspect that XML tag brackets may be creating problems as input parameter. I was told that to post XML data using a named form parameter, I might need to encode XML before it is assigned to the parameter.
 
I tried to google about encoding XML but couldn't find much information.
 
Any idea about passing XML as parameter or other insight are truly appreciated.
 
Nick

Charls K V

unread,
Nov 10, 2018, 5:57:54 AM11/10/18
to Oracle PL/SQL
Hi Nick,

I am getting the same error message for one of my web service calls. I too have two parameters to pass in the url. However it is not as complex as yours, my parameters are static string values.

Were you able to find the root cause of this issue? Any pointers to solve this issue will be appreciated.

Thanks,
Charls
Reply all
Reply to author
Forward
0 new messages