PL SQL UTL_HTTP Restful 网络服务调用不工作
PL SQL UTL_HTTP Restful web service call not working
我创建了一个过程,它使用 UTL_HTTP 包从 Oracle 11.2 服务器调用 restful Web 服务。这是一个 post 请求,我发送了一个阿拉伯值以及其他定义为 varchar2 的数据。
阿拉伯语字符串作为“???? ?????”发送到我在日志记录中检查过的 Web 服务。我将正文设置为 UTF-8,数据库服务器字符集为 "AR8ISO8859P6".
我尝试了转换函数和所有可能的方法。我不知道如何修复它。
找到下面的代码。
t_request_body :=
'{
"ArabicValue":"'
|| p_arabic_value
|| '",
"EnglishValue":"'
|| p_english_value
|| '"
}';
UTL_HTTP.set_transfer_timeout (5);
t_http_req :=
UTL_HTTP.begin_request
('webservice_url',
'POST',
'HTTP/1.1'
);
/*Describe in the request-header*/
UTL_HTTP.SET_BODY_CHARSET('UTF-8');
UTL_HTTP.set_header (t_http_req, 'Content-Type', 'application/json;charset=UTF-8');
UTL_HTTP.set_header (t_http_req, 'Content-Length', LENGTH (t_request_body));
UTL_HTTP.set_header (t_http_req, 'TransactionId', t_transaction_id);
UTL_HTTP.set_header (t_http_req, 'Accept', 'application/xml');
/*Put the data in de body of the request*/
UTL_HTTP.write_text (t_http_req, t_request_body);
/*Web service call*/
t_http_resp := UTL_HTTP.get_response (t_http_req);
/*Reading transaction id from header*/
UTL_HTTP.get_header_by_name (t_http_resp, 'TransactionId', t_trans);
英文值参数正在传递给 Web 服务。阿拉伯语值为“?????? ????”。我尝试了 oracle 中可用的转换函数将其转换为 UTF-8。也不行。
使用以下内容:
length_bytes := 长度(utl_raw.convert(utl_raw.cast_to_raw(t_request_body), 'AL32UTF8', 'AR8ISO8859P6'));
UTL_HTTP.set_header (t_http_req, 'Content-Length', length_bytes);
UTL_HTTP.write_raw (t_http_req, t_request_body);
我创建了一个过程,它使用 UTL_HTTP 包从 Oracle 11.2 服务器调用 restful Web 服务。这是一个 post 请求,我发送了一个阿拉伯值以及其他定义为 varchar2 的数据。
阿拉伯语字符串作为“???? ?????”发送到我在日志记录中检查过的 Web 服务。我将正文设置为 UTF-8,数据库服务器字符集为 "AR8ISO8859P6".
我尝试了转换函数和所有可能的方法。我不知道如何修复它。
找到下面的代码。
t_request_body :=
'{
"ArabicValue":"'
|| p_arabic_value
|| '",
"EnglishValue":"'
|| p_english_value
|| '"
}';
UTL_HTTP.set_transfer_timeout (5);
t_http_req :=
UTL_HTTP.begin_request
('webservice_url',
'POST',
'HTTP/1.1'
);
/*Describe in the request-header*/
UTL_HTTP.SET_BODY_CHARSET('UTF-8');
UTL_HTTP.set_header (t_http_req, 'Content-Type', 'application/json;charset=UTF-8');
UTL_HTTP.set_header (t_http_req, 'Content-Length', LENGTH (t_request_body));
UTL_HTTP.set_header (t_http_req, 'TransactionId', t_transaction_id);
UTL_HTTP.set_header (t_http_req, 'Accept', 'application/xml');
/*Put the data in de body of the request*/
UTL_HTTP.write_text (t_http_req, t_request_body);
/*Web service call*/
t_http_resp := UTL_HTTP.get_response (t_http_req);
/*Reading transaction id from header*/
UTL_HTTP.get_header_by_name (t_http_resp, 'TransactionId', t_trans);
英文值参数正在传递给 Web 服务。阿拉伯语值为“?????? ????”。我尝试了 oracle 中可用的转换函数将其转换为 UTF-8。也不行。
使用以下内容:
length_bytes := 长度(utl_raw.convert(utl_raw.cast_to_raw(t_request_body), 'AL32UTF8', 'AR8ISO8859P6'));
UTL_HTTP.set_header (t_http_req, 'Content-Length', length_bytes);
UTL_HTTP.write_raw (t_http_req, t_request_body);