UTL_HTTP.REQUEST_PIECES ou UTL_HTTP.WRITE_TEXT?

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
Responder
iliscio
Rank: Estagiário Júnior
Rank: Estagiário Júnior
Mensagens: 1
Registrado em: Sex, 14 Set 2018 11:33 am

Bom dia!

Pessoal,
Estou tratando algumas integrações dentro da empresa e notei que algumas integrações antigas fazem as requisições através do método UTL_HTTP.REQUEST_PIECES, enquanto para as novas que estamos desenvolvendo utilizamos o método UTL_HTTP.WRITE_TEXT.

Gostaria de saber de vocês se existe alguma diferença em relação a elas e qual, no ponto de vista de vocês, seria a mais adequada nos dias de hoje.

Desde já obrigado,
Igor Liscio.
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5024
Registrado em: Seg, 03 Mai 2004 3:08 pm
Localização: Portland, OR USA
Contato:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

São duas coisas diferentes.

Veja, no manual oficial explica:
https://docs.oracle.com/database/121/AR ... ARPLS71112
REQUEST and REQUEST_PIECES take a string uniform resource locator (URL), contact that site, and return the data (typically HTML) obtained from that site.

You should not expect REQUEST or REQUEST_PIECES to succeed in contacting a URL unless you can contact that URL by using a browser on the same machine (and with the same privileges, environment variables, and so on.)

If REQUEST or REQUEST_PIECES fails (for example, if it raises an exception, or if it returns an HTML-formatted error message, but you believe that the URL argument is correct), then try contacting that same URL with a browser to verify network availability from your machine. You may have a proxy server set in your browser that needs to be set with each REQUEST or REQUEST_PIECES call using the optional proxy parameter.
Em outras palavras, o comando REQUEST busca o que tiver em uma URL.
WRITE_TEXT Procedure
This procedure writes some text data in the HTTP request body. As soon as some data is sent as the HTTP request body, the HTTP request headers section is completed. Text data is automatically converted from the database character set to the request body character set.
Aqui tem um exemplo com Write_text: http://psoug.org/reference/utl_http.html

Selecionar tudo

DECLARE
 data VARCHAR2(1024) := '...';
 req  utl_http.req;
 resp utl_http.resp;
BEGIN
  req := utl_http.begin_request('http://www.psoug.org/about', 'POST');
  utl_http.set_header(req, 'Content-Length', length(data));

  -- Ask HTTP server to return "100 Continue" response
  utl_http.set_header(req, 'Expect', '100-continue');
  resp := utl_http.get_response(req, TRUE);

  -- Check for and dispose "100 Continue" response
  IF (resp.status_code <> 100) THEN
    utl_http.end_response(resp);
    raise_application_error(20000, 'Request rejected');
  END IF;

  utl_http.end_response(resp);

  -- Now, send the request body
  utl_http.write_text(req, data);

  -- Get the regular response
  resp := utl_http.get_response(req);
  utl_http.read_text(resp, data);

  utl_http.end_response(resp);
END;
/
Responder
  • Informação
  • Quem está online

    Usuários navegando neste fórum: Nenhum usuário registrado e 19 visitantes