从oracle pl / sql调用Restful webservice

时间:2017-05-13 07:03:14

标签: web-services rest plsql

我从 pl / sql 中调用 restful API。 restful api使用http而不是https,但它给了我以下错误 -

**ORA-29266: end-of-body reached**. I have write the following code---

   DECLARE
      lo_req            UTL_HTTP.req;
      lo_resp           UTL_HTTP.resp;
      HTTP_REQ          UTL_HTTP.REQ;
      HTTP_RESP         UTL_HTTP.RESP;
      t_http_resp       UTL_HTTP.resp;
      l_response_text   CLOB;
      v_url             VARCHAR2 (1024);
      pAllparameter     VARCHAR2 (1024);
      vSms              VARCHAR2(1024):='Hellow How Are Yoy';
   BEGIN
      UTL_HTTP.set_detailed_excp_support (TRUE);
      lo_req :=
         UTL_HTTP.
          begin_request ('URL'
            || 'smsText='
            || vSms
            || '&mobileNo='
            || pMobileNo,
            'POST',
            UTL_HTTP.HTTP_VERSION_1_1);
      lo_resp := UTL_HTTP.get_response (lo_req);
    UTL_HTTP.read_text (lo_resp, l_response_text);
      -- A successfull request would have the status code "200".
    -- DBMS_OUTPUT.put_line (l_response_text);
  UTL_HTTP.end_response (lo_resp);
    --  DBMS_OUTPUT.PUT_LINE (pAllparameter);
  EXCEPTION
     WHEN OTHERS
     THEN
        UTL_HTTP.end_response (lo_resp);
         RAISE;
   END;

当我调用过程时它给我错误。

请帮帮我..

1 个答案:

答案 0 :(得分:0)

如果启用了ORA-29266: end-of-body,它将在到达HTTP响应结束时始终引发异常detailed_exception。请参阅here

我通常循环遍历响应体(以防它比预期的长),然后我明确地捕获这个异常,即使我没有做任何事情,除了loggin身体已经结束

   DECLARE
      lo_req            UTL_HTTP.req;
      lo_resp           UTL_HTTP.resp;
      HTTP_REQ          UTL_HTTP.REQ;
      HTTP_RESP         UTL_HTTP.RESP;
      t_http_resp       UTL_HTTP.resp;
      l_response_text   CLOB;
      v_url             VARCHAR2 (1024);
      pAllparameter     VARCHAR2 (1024);
      vSms              VARCHAR2(1024):='Hellow How Are Yoy';
      buffer            VARCHAR2(4000);
   BEGIN
      UTL_HTTP.set_detailed_excp_support (TRUE);
      lo_req :=
         UTL_HTTP.
          begin_request ('URL'
            || 'smsText='
            || vSms
            || '&mobileNo='
            || pMobileNo,
            'POST',
            UTL_HTTP.HTTP_VERSION_1_1);
      lo_resp := UTL_HTTP.get_response (lo_req);
    BEGIN
      LOOP
        utl_http.read_line(lo_resp, buffer);
        l_response_text := l_response_text || buffer;
      END LOOP;
    EXCEPTION
    WHEN utl_http.end_of_body THEN
      utl_http.end_response(res);
    END;
  END;