HTTP Call Example
> HTTP call
For example we will call 'Currency Converter - Google Finance' to get conversion rate from GBP to EUR
URL: http://www.google.co.uk/finance/converter?a=1&from=GBP&to=EUR
>Part of the source code (right click > view source)
--
declare
l_url varchar2(100);
l_call utl_http.html_pieces;
l_source_code utl_http.html_pieces;
l_all_source varchar2(32767);
l_rate number;
begin
-- The URL
l_url := 'http://www.google.co.uk/finance/converter?a=1' ||
'&from=' || 'GBP' || '&to=' || 'EUR';
-- Make an HTTP call
l_call := utl_http.request_pieces(l_url);
for i in 1..l_call.count loop
--Get all the lines from the source code returned
l_source_code := utl_http.request_pieces(l_url,32767);
l_all_source := l_all_source||l_source_code(i);
end loop;
l_rate := substr(l_all_source,instr(l_all_source,'bld>')+4,6);
dbms_output.put_line('Rate: '||l_rate);
exception
when others then
dbms_output.put_line('Error: '||sqlerrm);
end;
For example we will call 'Currency Converter - Google Finance' to get conversion rate from GBP to EUR
URL: http://www.google.co.uk/finance/converter?a=1&from=GBP&to=EUR
>Part of the source code (right click > view source)
--
declare
l_url varchar2(100);
l_call utl_http.html_pieces;
l_source_code utl_http.html_pieces;
l_all_source varchar2(32767);
l_rate number;
begin
-- The URL
l_url := 'http://www.google.co.uk/finance/converter?a=1' ||
'&from=' || 'GBP' || '&to=' || 'EUR';
-- Make an HTTP call
l_call := utl_http.request_pieces(l_url);
for i in 1..l_call.count loop
--Get all the lines from the source code returned
l_source_code := utl_http.request_pieces(l_url,32767);
l_all_source := l_all_source||l_source_code(i);
end loop;
l_rate := substr(l_all_source,instr(l_all_source,'bld>')+4,6);
dbms_output.put_line('Rate: '||l_rate);
exception
when others then
dbms_output.put_line('Error: '||sqlerrm);
end;
No comments:
Post a Comment