The webservice expects this:
Post to
http://{IP/DNS}/upload/upload2tickets.php Body parameters:
KEY VALUE
file (required) 111.pdf file to send
DECLARE
req utl_http.req;
resp utl_http.resp;
v_content blob;
amount number := 2000;
req_length NUMBER;
v_offset NUMBER := 1;
v_buffer varchar2(4000);
l_response_header_name varchar2(256);
l_response_header_value varchar2(1024);
l_request_body clob;
l_response_body varchar2(32767);
BEGIN
-- The image file
SELECT hd.hdk_anexo_1
INTO v_content
FROM table hd
WHERE hd.hdk_id = 999;
utl_http.set_wallet(
path => 'file:/xxx/apps/xxx/xxx/19.0.0/wallet',
password => 'password'
);
utl_http.set_proxy ('proxy.xxx.xxx:8080');
req := utl_http.begin_request(
url => 'https://cloudcc.nos.pt/upload/upload2tickets.php',
method => 'POST',
http_version => 'HTTP/1.1'
);
utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
utl_http.set_header(req, 'Authorization', 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJpZmFwLmNsb3VkY2Mubm9zLnB0IiwiaXNzVXVpZCI6IjdlNGU1OGQwLWM3NDAtNDA2Ni05YzY1LWY3NmQzY2Y2MDE0OSIsImp0aSI6IjQwZDViZjMwLWYwNDktNDM3Yy1iYTFhLTk4MmUxODFiYmQ5ZCIsIm5hbWUiOiJ1c2VyX2FwaSIsInBlcm0iOltdLCJyYW5nZUxpc3QiOltdLCJpYXQiOjE1ODU1Nzc1MzYsImV4cCI6MTU4NjE4MjMzNn0.fHWRbxOUtTx-zb-14AeCBaL-8U5BbpinuW7tYtqzh');
utl_http.set_header(req, 'content-type', 'image/jpeg');
req_length := dbms_lob.getlength(v_content);
if req_length <= 32767 then
utl_http.set_header(req, 'Content-Length', req_length);
utl_http.write_raw(req, v_content);
elsif req_length > 32767 THEN
utl_http.set_header(req, 'Transfer-Encoding', 'Chunked');
while (v_offset < req_length) LOOP
dbms_lob.read(v_content, amount, v_offset, v_buffer);
utl_http.write_raw(req, v_buffer);
v_offset := v_offset + amount;
end loop;
end if;
resp := UTL_HTTP.get_response(req);
for i in 1 .. utl_http.get_header_count(resp) loop
utl_http.get_header(resp, i, l_response_header_name, l_response_header_value);
dbms_output.put_line('Response Header> ' || l_response_header_name || ': ' || l_response_header_value);
end loop;
utl_http.read_text(resp, l_response_body, 32767);
dbms_output.put_line('Response body>');
dbms_output.put_line(l_response_body);
-- Process the response from the HTTP call
IF resp.status_code = utl_http.HTTP_OK AND resp.reason_phrase = 'OK' THEN
dbms_output.put_line ('Webservice without errors');
ELSE
dbms_output.put_line ('Webservice errors=' || resp.status_code || '-' || resp.reason_phrase);
END IF;
utl_http.end_response (resp);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line ('ERROR Others=' || SQLERRM);
utl_http.end_response (resp);
END;
Result:
Response Header> Date: Thu, 02 Apr 2020 15:49:30 GMT
Response Header> Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.4.16
Response Header> X-Powered-By: PHP/5.4.16
Response Header> Expires: Thu, 19 Nov 1981 08:52:00 GMT
Response Header> Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Response Header> Pragma: no-cache
Response Header> Vary: Origin
Response Header> Content-Length: 45
Response Header> Connection: close
Response Header> Content-Type: text/html; charset=UTF-8
Response body>
{"uuid":"","info":null,"error":"","file":[]}
Webservice without errors
It was suposed to return a value in the "uuid" field, but it comes out empty.
However, i also question if this is suppose to work, since the WS spec states a Key/Value pair.
Maybe it only works that way and not like my code tries to do, since if i call it from Postman with the Key/Value in form-data, it works !!
I don't know what Postman does in the background, but i get the feeling i must include the "file" key, somewhere in my code!
Alternatively, i also tried to mimmick Postman and include in the body:
{
"file":"oracle_directory/filename"
}
but no luck !