aris_datuin
asked on
UTL_HTTP using Post method sample code
Hi experts, I am trying to pass a string to a servlet. The string is too long and cannot use the get method because of the limitation the get method has. I need a sample code of utl_http using the post method to pass the string. I think it has something to do with utl_http.write_text() but can't make it to work.
Here is my code... I hope you could help me with this... thanks in advanced...
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
declare
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := 'http://10.100.100.106:8888/Global/testPost.do';
name varchar2(4000);
buffer varchar2(4000);
test VARCHAR2(1000):='xxx';
content varchar2(4000) := 'paramKey='||test;
begin
req := utl_http.begin_request(url , 'POST',' HTTP/1.1');
utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req, 'content-type', 'text/html');
utl_http.set_header(req, 'Content-Length', length(content));
utl_http.write_text(req, content);
res := utl_http.get_response(req) ;
begin
loop
utl_http.read_line(res, buffer);
dbms_output.put_line(buffe r);
end loop;
utl_http.end_response(res) ;
exception
when utl_http.end_of_body then
utl_http.end_response(res) ;
end;
end;
/
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---
Here is my code... I hope you could help me with this... thanks in advanced...
--------------------------
declare
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := 'http://10.100.100.106:8888/Global/testPost.do';
name varchar2(4000);
buffer varchar2(4000);
test VARCHAR2(1000):='xxx';
content varchar2(4000) := 'paramKey='||test;
begin
req := utl_http.begin_request(url
utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req, 'content-type', 'text/html');
utl_http.set_header(req, 'Content-Length', length(content));
utl_http.write_text(req, content);
res := utl_http.get_response(req)
begin
loop
utl_http.read_line(res, buffer);
dbms_output.put_line(buffe
end loop;
utl_http.end_response(res)
exception
when utl_http.end_of_body then
utl_http.end_response(res)
end;
end;
/
--------------------------
ASKER
If my understanding is correct, my problem is how will I pass a String into UTL_HTTP using Post method... and how will I receive the corresponding return of the said UTL_HTTP...
for some reason, my code above is not working...
may I ask how will I do this...
thanks again... =)
for some reason, my code above is not working...
may I ask how will I do this...
thanks again... =)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi, may I ask if I still need to modify something in the line
UTL_HTTP.Set_Header(req, 'Content-Type', 'application/x-www-form-ur lencoded') ;
thanks again... =)
UTL_HTTP.Set_Header(req, 'Content-Type', 'application/x-www-form-ur
thanks again... =)
i have used utl_http pack to post data to a webservice and my header setting was like that.
so i offered you to try that. it is not related with utl_http.read_text function usage.
regards.
so i offered you to try that. it is not related with utl_http.read_text function usage.
regards.
ASKER
hi concon...
utl_http.read_text solves my problem...
thanks... =)
utl_http.read_text solves my problem...
thanks... =)
Even I am trying to pass string to a servlet through HTTP POST, but i am not receiving any params at servlet. I am receiving only the headers and not the body which has data in servlet side. ( Even I wrote Java Server scocket progrem to read the contents posted at port 8080 but I am not receiving the data, I can see only the HTTP headers and no body)
declare
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := 'http://localhost:8080/TestServlet';
name varchar2(4000);
buffer varchar2(4000);
test VARCHAR2(1000):='xxx';
content varchar2(4000) := 'paramKey='||test;
begin
req := utl_http.begin_request(url , 'POST',' HTTP/1.1');
utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req, 'content-type', 'text/html');
utl_http.set_header(req, 'Content-Length', length(content));
utl_http.write_text(req, content);
res := utl_http.get_response(req) ;
begin
loop
utl_http.read_line(res, buffer);
dbms_output.put_line(buffe r);
end loop;
utl_http.end_response(res) ;
exception
when utl_http.end_of_body then
utl_http.end_response(res) ;
end;
end;
/
declare
req utl_http.req;
res utl_http.resp;
url varchar2(4000) := 'http://localhost:8080/TestServlet';
name varchar2(4000);
buffer varchar2(4000);
test VARCHAR2(1000):='xxx';
content varchar2(4000) := 'paramKey='||test;
begin
req := utl_http.begin_request(url
utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req, 'content-type', 'text/html');
utl_http.set_header(req, 'Content-Length', length(content));
utl_http.write_text(req, content);
res := utl_http.get_response(req)
begin
loop
utl_http.read_line(res, buffer);
dbms_output.put_line(buffe
end loop;
utl_http.end_response(res)
exception
when utl_http.end_of_body then
utl_http.end_response(res)
end;
end;
/
if you have a proxy setting then you need to use
utl_http.set_proxy('proxy_
Regards.