2 Replies Latest reply on May 1, 2012 8:22 AM by user8698687

    Unable to post variables using utl_http

      Hi guys I hope you can help me out.

      I'm having issues posting variables using the built in package utl_http. Its installed and I can retrieve web pages but I can't post variables. I was trying to use a simple web service when I came across the problem. While trying to fix it, I have broken it right down to point where I can't go any further.

      I'm currently testing it using a site called posttestserver.com. You call the url in your code (see below) and you dump your variables and it tells what it has recieved.

      The following code works, it retrieves http from google.com, and I think it confirms that I can get web page info using utl_http

      select utl_http.request('http://google.com') from dual

      However the reply I get from the following code tells me that no variables have been read by the api. I get a similar response when trying to call a normal web service


      vRequest Utl_Http.req;
      vPostText VARCHAR2(500);
      vLogin VARCHAR2(500);
      vResponse Utl_Http.resp;
      --vResponseText VARCHAR2(5000);
      vResponseText clob;
      vErrorText clob;
      v_action varchar2(20) := 'sendsms';


      vPostText := 'par1=5'||'&'||'par2=7'||'&'||'par3=9';

      utl_http.set_proxy(apex_application.g_proxy_server, NULL);


      vRequest := Utl_Http.begin_request('http://posttestserver.com/post.php', 'POST');
      utl_http.set_header(vRequest, 'Proxy-Connection', 'KeepAlive');
      utl_http.set_header (vRequest, 'Connection', 'Keep-Alive');
      utl_http.set_header(vRequest, 'Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');

      utl_http.write_text(vRequest, vPostText);
      vResponse := utl_http.get_response(vRequest);
      Utl_Http.read_text(vResponse, vResponseText);


      END ;

      I'm guessing that it is something in my environment - but I've pulling my hair out with this one.

      If you have any ideas that would be great. Oracle XE 10g, Application Express

      Cheers, TIA

        • 1. Re: Unable to post variables using utl_http
          Hi Ade,

          I don't think this is an XE specific question, but this forum is dedicated to the Express Edition of Oracle Database. Experts for questions like yours are probably to be found in {forum:id=75} or, as it seems you have an APEX application as target, perhaps in {forum:id=137}.
          And it would have been helpful if you would have provided the actual error message(s) you received when running that block.

          I'll try to put my knowledge in here anyway. From what I can see, you have a persistent connection:
          utl_http.set_header(vRequest, 'Proxy-Connection', 'KeepAlive');
          utl_http.set_header (vRequest, 'Connection', 'Keep-Alive');
          ... and you want to submit a form:
          utl_http.set_header(vRequest, 'Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');

          utl_http.write_text(vRequest, vPostText);
          ... and expect to get an answer right afterwards:
          vResponse := utl_http.get_response(vRequest);
          The server would usually wait for your request to finish somehow before it starts to answer... But how should the server know that your request ended already? You neither close the connection nor do you provide a header stating the 'Content-Length' of your body. I'm not sure this is the (only) problem in that case, but I'd recomment to add the 'Content-Length' header, e.g.
          utl_http.set_header(vRequest, 'Content-Length', length(vPostText));
          I hope this helps you solve your problem. If not, please think of the points I mentioned above...