首页 > 解决方案 > 在 Oracle PLSQL 中使用 UTL_HTTP 调用 Rest Webservice 时出错

问题描述

使用 utl_http 调用休息服务时,我得到以下错误响应。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">

<HTML><HEAD><TITLE>Bad Request</TITLE>

<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>

<BODY><h2>Bad Request</h2>

<hr><p>HTTP Error 400. The request is badly formed.</p>

</BODY></HTML>

URL:https://主机名/svc/snservice-consolidation/v2.0/api/sn/GetSNDetails?Out=CAE&Mode=XML

伪代码:

 UTL_HTTP.set_wallet (
  'file:/var/opt/oracle/wallets/........',
  'xxxxxxx');

l_url :='https://<hostname>/svc/snservice-consolidation/v2.0/api/sn/GetSNDetails?Out=CAE'
  || CHR (38)
  || 'Mode=XML';

l_http_request := UTL_HTTP.begin_request (l_url, 'POST', 'HTTPS/1.1');


UTL_HTTP.set_authentication (l_http_request,'UN','PWD');

p_req_clob := TO_CLOB ('<root>
                       <Device SerialNumber="AAAAAAAAAA"/>
                       </root>'
                       );

UTL_HTTP.set_header (l_http_request, 'Content-Type', 'text/xml');
UTL_HTTP.set_header (l_http_request,
                    'Content-Length',
                    LENGTH (p_req_clob));
UTL_HTTP.write_text (l_http_request, p_req_clob);
l_http_response := UTL_HTTP.get_response (l_http_request);

补充说明:

  1. 相同的 Web 服务在 Postman 等其他客户端中运行良好
  2. 相同的后端代码适用于另一个接受相同数据输入的类似服务。

感谢您对此事的任何帮助。提前致谢。

问候,查尔斯

标签: oracleplsql

解决方案


试试这个:

l_http_request := UTL_HTTP.begin_request (l_url, 'POST', 'HTTP/1.1');

推荐阅读