ult_http [message #575568] |
Thu, 24 January 2013 04:02  |
 |
limner
Messages: 9 Registered: January 2013 Location: Rome
|
Junior Member |
|
|
Good Morning to everyone.
I have a problem: i need to retrieve html using oracle and setting the correct user agent.
I used the ut_http package and his fuction utl_http.request_pages.
I worked perfectly for me, execpt that i could be able to setup the correct user-agent.
I read the documentation and i found that this instruction utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');
should fix my problem, but when i used it, nothing changed and the webserver didn't recognize the correct user agent.
I post downhere a piece of the pl-sql procedure i made (it seems that i could find the correct "link" between utl_http.set_header instruction and utl_http.request_pieces instruction)
while(ng < nmax)
loop
ch_in:=p_mese_elab||'-'||ng;
url:=url to retrieve;
req := UTL_HTTP.BEGIN_REQUEST(url);
UTL_HTTP.SET_HEADER(req, 'User-Agent', 'Mozilla/4.0');
resp := UTL_HTTP.GET_RESPONSE(req);
RISULTATO:=utl_http.request_pieces(url,99999);
delete temp_esamina
where data_ril = trunc(to_date(ch_in,'yyyy-mm-dd'));
step:=3;
i:=0;
for i in 1 .. RISULTATO.count
loop
step:=4;
select to_date(ch_in,'yyyy-mm-dd') into app_data from dual;
insert into temp_esamina
( testo
,data_ril
,num )
values ( RISULTATO(i)
,app_data
,i );
step:=5;
end loop;
UTL_HTTP.END_RESPONSE(resp);
ng:=ng+1;
ngg:=ngg+1;
end loop;
If someone could help me, it would be greately apreciated!
Samantha
|
|
|
Re: ult_http [message #575601 is a reply to message #575568] |
Thu, 24 January 2013 11:00   |
 |
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
It's probably me, but - I don't quite understand what you are saying. It is difficult to run code you posted because we don't have your tables (which you use in DELETE and INSERT statements); also, variables' declaration section is missing.
Perhaps you should rewrite it, but this time posting complete code, along with CREATE TABLE statement as well as URL you are testing the code with. Explain what you got (but aren't satisfied with (why not?)) and what you would like to get as a result. Then, people could run your code and try to help.
Finally: please, before posting your next message, format the code and enclose it into the CODE tags which will preserve formatting and make your code easier to read. If you don't know how to do that, check this; won't take more than several seconds.
|
|
|
|
Re: ult_http [message #575641 is a reply to message #575607] |
Fri, 25 January 2013 01:00   |
_jum
Messages: 577 Registered: February 2008
|
Senior Member |
|
|
You said Quote:that this instruction utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');
should fix my problem
What is the problem you try to fix ?
I didn't need to use utl_http.set_header until now, here is an example, that works with or without:
set serveroutput on unlimited
DECLARE
req utl_http.req;
resp utl_http.resp;
value VARCHAR2(1024);
BEGIN
req := utl_http.begin_request('http://www.orafaq.com/forum/t/140212/120300/');
--utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');
resp := utl_http.get_response(req);
FOR i IN 1..100
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;
/
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="description" content="Getting Data From the web without PL/SQL " />
<title>OraFAQ Forum: SQL & PL/SQL » Getting Data From the web without PL/SQL</title>
<base href="http://www.orafaq.com/forum/" />
...
PL/SQL procedure successfully completed.
|
|
|
|
|
|
|
|
|
Re: ult_http [message #575834 is a reply to message #575829] |
Mon, 28 January 2013 05:14   |
_jum
Messages: 577 Registered: February 2008
|
Senior Member |
|
|
The code still workes for me (ORACLE 11.2.0.3.0), so check your URL in utl_http.begin_request.
|
|
|
Re: ult_http [message #575837 is a reply to message #575829] |
Mon, 28 January 2013 05:34  |
 |
Michel Cadot
Messages: 68757 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
In addition, the Action part tells you what to first do: "Use get_detailed_sqlerrm to check the detailed error message.".
Regards
Michel
|
|
|