UTL_HTTP не имеет такой функциональности (и, возможно, содержит некоторые ошибки), но вы можете попробовать использовать Java Хранимые процедуры. Это намного более гибко, и я исправил ошибку «Ошибка проверки сертификата» только таким способом.
Существует пример функции запроса POST:
CREATE OR REPLACE JAVA SOURCE NAMED "example/HttpUtil" AS
import javax.net.ssl.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.cert.X509Certificate;
import java.sql.Blob;
public class HttpUtil {
public static boolean doRequest(String link, Blob requestBody, Blob[] responseBody, String[] message) {
String res = "Success";
boolean result = true;
try {
request(link,requestBody,responseBody);
} catch (Exception ex) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
res = sw.toString();
result = false;
}
message[0] = res;
return result;
}
public static void request(String link, Blob requestBody, Blob[] responseBody) throws Exception {
URL url = new URL(link);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Proxy-Connection", "Keep-Alive");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
con.setRequestProperty("Content-Length", String.valueOf(requestBody.length()));
DataOutputStream outputStream = new DataOutputStream(con.getOutputStream());
InputStream reqStream = requestBody.getBinaryStream();
byte[] buff = new byte[1024];
int len = 0;
while ((len = reqStream.read(buff)) != -1) {
outputStream.write(buff, 0, len);
}
int status = con.getResponseCode();
InputStream in;
if (status >= 400) {
in = con.getErrorStream();
} else {
in = con.getInputStream();
}
OutputStream out = responseBody[0].setBinaryStream(0);
byte[] buf = new byte[1024];
int n;
while (-1 != (n = in.read(buf))) {
out.write(buf, 0, n);
}
in.close();
con.disconnect();
out.flush();
}
}
/
ALTER JAVA SOURCE "example/HttpUtil" COMPILE;
CREATE OR REPLACE FUNCTION http_request (is_url IN VARCHAR2,
i_body IN BLOB,
io_resp IN OUT NOCOPY BLOB,
o_message OUT VARCHAR2)
RETURN BOOLEAN
AS LANGUAGE JAVA
NAME 'HttpUtil.doRequest(java.lang.String, java.sql.Blob, java.sql.Blob[], java.lang.String[]) return boolean';