仅当URL变为LONG时,ORA-29263才会抛出错误

时间:2018-02-28 11:42:24

标签: oracle http oracle11g request

我正试图从我的okg pkg拨打一份宁静的服务;有时使用相同的代码,成功到达此服务并返回响应;但是当网址中的邮件变得更长时==> ORA-29273 http请求和ORA-29263 http协议被抛出;我不会在通话之间改变任何内容,只会从此网址发送消息;以下是我的程序:

PROCEDURE SEND_SMS(username   VARCHAR2,
                   password   VARCHAR2,
                   phone      VARCHAR2,
                   message    VARCHAR2,
                   code       VARCHAR2,                 
                   P_RESPONSE OUT VARCHAR2) AS

    v_request         UTL_HTTP.req;
    v_response        UTL_HTTP.resp;
    v_text            VARCHAR2(1024);
    v_url             VARCHAR2(1024);
    v_message         VARCHAR2(1024);


  BEGIN
    BEGIN

      P_RESPONSE := '';
      v_message  := REPLACE(message,' ', '%20');


      v_url             := 'http://myservicelink.com/SendSMS?strUsername=' |
                           username || '&strPassword=' || password ||
                           '&strPhone=' || phone || '&strcode=' || code ||
                           '&strMessage=' || v_message;
      v_request         := UTL_HTTP.begin_request(v_url);

      DBMS_OUTPUT.put_line(v_url);

      v_response := UTL_HTTP.get_response(v_request);

      LOOP
        BEGIN
          UTL_HTTP.read_text(v_response, v_text);
          DBMS_OUTPUT.put_line(v_text);
        EXCEPTION
          WHEN UTL_HTTP.end_of_body THEN
            NULL;
        END;

        EXIT WHEN v_text IS NULL;
      END LOOP;

      UTL_HTTP.end_response(v_response);

      IF v_response.status_code <> 200 THEN
        P_RESPONSE := v_response.reason_phrase;
      END IF;

    EXCEPTION
      WHEN OTHERS THEN
       P_RESPONSE := 'An error has occured: ' || SQLERRM;
    END;

  END SEND_SMS;

因此,当v_message变长时,抛出异常。可能是什么错误;请注意,从具有相同输入的ORA pkg外部调用相同的链接 - &gt;达到了myservice;

以下是我工作讯息的模板: Dear X, you have been registered to our app. You can download the app for iPhone at link of app store or for android at link of

不工作: Dear X, you have been registered to our app. You can download the app for iPhone at link of app store or for android at link of play store your

1 个答案:

答案 0 :(得分:1)

你的两个字符串之间的区别不仅仅是长度;第二个也有一个换行符。您正在使用以下内容替换空格:

v_message  := REPLACE(message,' ', '%20');

但这不会与任何其他非法角色打交道。

如果您将其更改为使用the utl_url.escape() function

v_message  := utl_url.escape(message);

然后它也将转义新行,所以你最后得到第一条消息(与当前代码相同):

  

Dear%20X,%20you%20have%20been%20registered%20to%20our%20app.%20You%20can%20download%20the%20app%20for%20iPhone%20at%20link%20of%20app%20store%20or%20for%20android%20at%20link%20of

但这是第二次:

  

Dear%20X,%20you%20have%20been%20registered%20to%20our%20app.%20You%20can%20download%20the%20app%20for%20iPhone%20at%20link%20of%20app%20store%20or%20for%20android%20at%20link%20of%20play%20store%0Ayour

换行符已编码为%0A。根据消息中的其他内容,您可能需要将true作为第二个参数传递,而不是将其默认为false;差异在上面的文档链接中解释。