Discussion:
Problems getting UTL_HTTP example from Oracle doc to work (client error 400 -- bad request)
(too old to reply)
Robert Holcomb
2004-11-18 17:51:55 UTC
Permalink
All,

Below is the description of my problem. I've taken sample code
directly out of the Oracle documentation
(http://www.di.unipi.it/~ghelli/bdl/B10501_01/appdev.920/a96612/u_http.htm#1013135)
and it doesn't work. I've slightly modified the example code to point
at www.yahoo.com and commented out the proxy statement (because in IE
I don't have a proxy set and my network doesn't have a proxy server).
I get the error indicated at the bottom of this post.

My version information
---------------------------------------
Oracle9i Release 9.2.0.1.0 - Production
JServer Release 9.2.0.1.0 - Production


Example from Oracle documentation: Using UTL_HTTP
---------------------------------------

SET serveroutput ON SIZE 40000

DECLARE
req utl_http.req;
resp utl_http.resp;
value VARCHAR2(1024);
BEGIN

utl_http.set_proxy('proxy.my-company.com', 'corp.my-company.com');

req := utl_http.begin_request('http://www-hr.corp.my-company.com');
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;



My slightly modified version of the example code (changed URL and
commented out proxy)
---------------------------------------

SET serveroutput ON SIZE 40000

DECLARE
req utl_http.req;
resp utl_http.resp;
value VARCHAR2(1024);
BEGIN

-- utl_http.set_proxy('proxy.my-company.com',
'corp.my-company.com');

req := utl_http.begin_request('http://www.yahoo.com');
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;



Error response when this code is executed in SQL Plus
---------------------------------------

SQL> SET serveroutput ON SIZE 40000
SQL>
SQL> DECLARE
2 req utl_http.req;
3 resp utl_http.resp;
4 value VARCHAR2(1024);
5 BEGIN
6
7 -- utl_http.set_proxy('proxy.my-company.com',
'corp.my-company.com');
8
9 req := utl_http.begin_request('http://www.yahoo.com');
10 utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');
11 resp := utl_http.get_response(req);
12 LOOP
13 utl_http.read_line(resp, value, TRUE);
14 dbms_output.put_line(value);
15 END LOOP;
16 utl_http.end_response(resp);
17 EXCEPTION
18 WHEN utl_http.end_of_body THEN
19 utl_http.end_response(resp);
20 END;
21 /
DECLARE
*
ERROR at line 1:
ORA-29268: HTTP client error 400 - Bad Request
ORA-06512: at "SYS.UTL_HTTP", line 1220
ORA-06512: at line 11

Thanks in advance for your help!

Rob
Yong Huang
2004-11-22 04:53:04 UTC
Permalink
Post by Robert Holcomb
All,
Below is the description of my problem. I've taken sample code
directly out of the Oracle documentation
(http://www.di.unipi.it/~ghelli/bdl/B10501_01/appdev.920/a96612/u_http.htm#1013135)
and it doesn't work. I've slightly modified the example code to point
at www.yahoo.com and commented out the proxy statement (because in IE
I don't have a proxy set and my network doesn't have a proxy server).
I get the error indicated at the bottom of this post.
My version information
---------------------------------------
Oracle9i Release 9.2.0.1.0 - Production
JServer Release 9.2.0.1.0 - Production
...
Post by Robert Holcomb
Error response when this code is executed in SQL Plus
---------------------------------------
SQL> SET serveroutput ON SIZE 40000
SQL>
SQL> DECLARE
2 req utl_http.req;
3 resp utl_http.resp;
4 value VARCHAR2(1024);
5 BEGIN
6
7 -- utl_http.set_proxy('proxy.my-company.com',
'corp.my-company.com');
8
9 req := utl_http.begin_request('http://www.yahoo.com');
10 utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');
11 resp := utl_http.get_response(req);
12 LOOP
13 utl_http.read_line(resp, value, TRUE);
14 dbms_output.put_line(value);
15 END LOOP;
16 utl_http.end_response(resp);
17 EXCEPTION
18 WHEN utl_http.end_of_body THEN
19 utl_http.end_response(resp);
20 END;
21 /
DECLARE
*
ORA-29268: HTTP client error 400 - Bad Request
ORA-06512: at "SYS.UTL_HTTP", line 1220
ORA-06512: at line 11
Can you reproduce? I ran your code on my 10.1.0.2.0 database and got
the result correctly (ignore the line length overflow error):

SQL> @c:\q
<html><head>
<script language=javascript>
var now=new Date,t1=0,t2=0,t3=0,t4=0,t5=0,t6=0,hp=0,cc='',ylp='';t1=now.getTime();
</script>
<title>Yahoo!</title>
DECLARE
*
ERROR at line 1:
ORA-20000: ORU-10028: line length overflow, limit of 255 chars per
line
ORA-06512: at "SYS.DBMS_OUTPUT", line 35
ORA-06512: at "SYS.DBMS_OUTPUT", line 115
ORA-06512: at line 14

I don't think this is because I'm using 10g. Just try a few times and
also against other sites.

Yong Huang

Loading...