Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Error 400 Bad Request when Consume Web Service

arlopezaApr 15 2018 — edited Apr 16 2018

I'm trying to consume a Web Service using utl_http, I've read some docs about it and got it at first, but suddenly stop  working and appear an error message: "400 Bad Request", does any body knows what could it be?

create or replace procedure zSRIAutorizacionOffline(vCLave in varchar2) is

  l_http_request   utl_http.req;

  l_http_response  utl_http.resp;

  l_buffer_size    number(10) := 1024;

  l_string_request varchar2(32500);

  l_line           varchar2(32500);

  l_substring_msg  varchar2(32500);

  l_raw_data       raw(2500);

  l_clob_response  clob;

  vClave           varchar2(49);

  inicio           number;

  fin              number;

  respuesta        varchar2(2000);

  fecha            varchar2(50);

  l_host_name      varchar2(128) := 'https://cel.sri.gob.ec/comprobantes-electronicos-ws/AutorizacionComprobantesOffline?wsdl';

begin

utl_http.set_wallet('file:/u01/sri/certificado/wallet',

                      'PasswordInHere');

  l_string_request := '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ec="http://ec.gob.sri.ws.autorizacion">

   <soapenv:Header/>

   <soapenv:Body>

      <ec:autorizacionComprobante>

            <claveAccesoComprobante>' || vClave || '</claveAccesoComprobante>

      </ec:autorizacionComprobante>

   </soapenv:Body>

</soapenv:Envelope>';

  utl_http.set_transfer_timeout(60);

  l_http_request := utl_http.begin_request(url          => l_host_name,

                                           method       => 'POST',

                                           http_version => 'HTTP/1.1');

  utl_http.set_header(l_http_request,

                      'User-Agent',

                      'Mozilla/4.0');

  utl_http.set_header(l_http_request,

                      'Host',

                      l_host_name);

  utl_http.set_header(l_http_request,

                      'Connection',

                      'close');

  utl_http.set_header(l_http_request,

                      'Content-Type',

                      'text/xml;charset=UTF-8');

  utl_http.set_header(l_http_request,

                      'SOAPAction',

                      '');

  utl_http.set_header(l_http_request,

                      'Content-Length',

                      length(l_string_request));

  <<request_loop>>

  for i in 0 .. ceil(length(l_string_request) / l_buffer_size) - 1 loop

    l_substring_msg := substr(l_string_request,

                              i * l_buffer_size + 1,

                              l_buffer_size);

    begin

      l_raw_data := utl_raw.cast_to_raw(l_substring_msg);

      utl_http.write_raw(r    => l_http_request,

                         data => l_raw_data);

    exception

      when no_data_found then

        exit request_loop;

    end;

  end loop request_loop;

  l_http_response := utl_http.get_response(l_http_request);

  begin

    <<response_loop>>

    loop

      utl_http.read_raw(l_http_response,

                        l_raw_data,

                        l_buffer_size);

      l_clob_response := l_clob_response || utl_raw.cast_to_varchar2(l_raw_data);

    end loop response_loop;

  exception

    when utl_http.end_of_body then

      utl_http.end_response(l_http_response);

  end;

  l_line := substr(l_clob_response,

                   1,

                   32000);

end zSRIAutorizacionOffline;

This post has been answered by arlopeza on Apr 16 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 14 2018
Added on Apr 15 2018
10 comments
2,108 views