1

Topic: UTL_HTTP To send POST in UTF-8, basis in Win-1251

Hello.
I feel that I do not have not enough basic understanding of operation with codings and with HTTP and it is a shame to me. Help.
Oracle 10XE. It is necessary to send to a Web server the Cyrillic data, but come, probably, substituting characters. I test not on that service where it is necessary to send since they do not have test mode, and on found on Internet open spaces other service. The server receives from me :
http://prntscr.com/hg8nee
The code more low:

DECLARE
l_clob CLOB;
http_req UTL_HTTP.REQ;
http_resp UTL_HTTP.RESP;
url_text VARCHAR2 (32767);
lv_clob_length_bytes NUMBER;
v_url VARCHAR2 (500 CHAR);
v_content VARCHAR2 (100 CHAR);
BEGIN
v_content: = CONVERT ('  ', ' UTF8 ');
v_url: = ' http://putsreq.com/iLm1LN52ApNwd2nIKt ';
http_req: = utl_http.begin_request (v_url, ' POST ');
utl_http.set_header (http_req, ' User-Agent ', ' Mozilla/4.0 ');
utl_http.set_body_charset (http_req, ' UTF8 ');
utl_http.set_header (http_req, ' Content-Length ', LENGTHC (v_content));
utl_http.set_header (http_req, ' Content-Type ', ' text/json; charset=utf-8 ');
utl_http.write_text (http_req, v_content);
http_resp: = utl_http.get_response (http_req);
LOOP
BEGIN
url_text: = null;
utl_http.read_line (http_resp, url_text, TRUE);
l_clob: = l_clob || url_text;
EXCEPTION
WHEN OTHERS THEN EXIT;
END;
END LOOP;
UTL_HTTP.END_RESPONSE (http_resp);
dbms_output.put_line (l_clob);
END;
/

2

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

The tired developer;
Instead of write_text use write_raw. For conversion - utl_i18n. If an initial content in clob, dbms_lob.converttoblob.

3

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

UTL_I18N.STRING_TO_RAW

4

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

Here so? The garbage all the same came...

DECLARE
l_clob CLOB;
http_req UTL_HTTP.REQ;
http_resp UTL_HTTP.RESP;
url_text VARCHAR2 (32767);
lv_clob_length_bytes NUMBER;
v_url VARCHAR2 (500 CHAR);
v_content VARCHAR2 (100 CHAR);
BEGIN
v_content: = '  ';
v_url: = ' http://putsreq.com/ey7gCfEVYoq5qi0GZvA9 ';
http_req: = utl_http.begin_request (v_url, ' POST ');
utl_http.set_header (http_req, ' User-Agent ', ' Mozilla/4.0 ');
utl_http.set_body_charset (http_req, ' UTF8 ');
utl_http.set_header (http_req, ' Content-Length ', LENGTHC (v_content));
utl_http.set_header (http_req, ' Content-Type ', ' text/json; charset=utf-8 ');
utl_http.write_raw (http_req, UTL_I18N.STRING_TO_RAW (v_content));
http_resp: = utl_http.get_response (http_req);
LOOP
BEGIN
url_text: = null;
utl_http.read_line (http_resp, url_text, TRUE);
l_clob: = l_clob || url_text;
EXCEPTION
WHEN OTHERS THEN EXIT;
END;
END LOOP;
UTL_HTTP.END_RESPONSE (http_resp);
dbms_output.put_line (l_clob);
END;
/

5

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

the developer wrote:

Here so? The garbage All the same came...

1) You did not specify to the converter the target coding.
2) when utl_http.end_of_body then.

6

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

1. Precisely, more haste, less speed, I specify UTF8 now
2. Understood, added
Something still is impossible...

DECLARE
l_clob CLOB;
http_req UTL_HTTP.REQ;
http_resp UTL_HTTP.RESP;
url_text VARCHAR2 (32767);
lv_clob_length_bytes NUMBER;
v_url VARCHAR2 (500 CHAR);
v_content VARCHAR2 (100 CHAR);
BEGIN
v_content: = '  ';
v_url: = ' http://putsreq.com/ey7gCfEVYoq5qi0GZvA9 ';
http_req: = utl_http.begin_request (v_url, ' POST ');
utl_http.set_header (http_req, ' User-Agent ', ' Mozilla/4.0 ');
utl_http.set_body_charset (http_req, ' UTF8 ');
utl_http.set_header (http_req, ' Content-Length ', LENGTHC (v_content));
utl_http.set_header (http_req, ' Content-Type ', ' text/json; charset=utf-8 ');
utl_http.write_raw (http_req, UTL_I18N.STRING_TO_RAW (v_content, ' UTF8 '));
http_resp: = utl_http.get_response (http_req);
LOOP
BEGIN
url_text: = null;
utl_http.read_line (http_resp, url_text, TRUE);
l_clob: = l_clob || url_text;
EXCEPTION
WHEN UTL_HTTP.END_OF_BODY THEN
UTL_HTTP.END_RESPONSE (http_resp);
WHEN OTHERS THEN EXIT;
END;
END LOOP;
dbms_output.put_line (l_clob);
END;
/

7

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

the developer wrote:

Something still is impossible...

That is is specific?

8

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

The server still receives garbage, i.e., any substituting characters. As on a screen from the first post.

9

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

Acl do not allow me to be played.
Here you write the initial size of a content before conversion.

the developer wrote:

utl_http.set_header (http_req, ' Content-Length ', LENGTHC (v_content));

10

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

the developer wrote:

v_content: =>>> CONVERT (<<<'  '>>>, ' UTF8 ') <<<;

Throw out. And at all do not use never this envelope.
And length correctly count.

11

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

Elic, about, I waited for you, I saw, you often help about UTL_HTTP.
And thus that I read a row to those, to my shame, I missed length.
I already threw out an envelope, as you can see on the last posts.
Made so, but all the same garbage:

DECLARE
l_clob CLOB;
http_req UTL_HTTP.REQ;
http_resp UTL_HTTP.RESP;
url_text VARCHAR2 (32767);
lv_clob_length_bytes NUMBER;
v_url VARCHAR2 (500 CHAR);
v_content VARCHAR2 (100 CHAR);
v_raw_content RAW (1000);
BEGIN
v_content: = '  ';
v_raw_content: = UTL_I18N.STRING_TO_RAW (v_content, ' UTF8 ');
v_url: = ' http://putsreq.com/ey7gCfEVYoq5qi0GZvA9 ';
http_req: = utl_http.begin_request (v_url, ' POST ');
utl_http.set_header (http_req, ' User-Agent ', ' Mozilla/4.0 ');
utl_http.set_body_charset (http_req, ' UTF-8 ');
utl_http.set_header (http_req, ' Content-Length ', utl_raw.length (v_raw_content));
utl_http.set_header (http_req, ' Content-Type ', ' text/json; charset=utf-8 ');
utl_http.write_raw (http_req, v_raw_content);
http_resp: = utl_http.get_response (http_req);
LOOP
BEGIN
url_text: = null;
utl_http.read_line (http_resp, url_text, TRUE);
l_clob: = l_clob || url_text;
EXCEPTION
WHEN UTL_HTTP.END_OF_BODY THEN
UTL_HTTP.END_RESPONSE (http_resp);
WHEN OTHERS THEN EXIT;
END;
END LOOP;
dbms_output.put_line (l_clob);
END;
/

I correctly counted length now?

12

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

the developer wrote:

utl_http.set_body_charset (http_req, ' UTF-8 ');
utl_http.set_header (http_req, ' Content-Length ', utl_raw.length (v_raw_content));
utl_http.set_header (http_req, ' Content-Type ', ' text/json; charset=utf-8 ');
utl_http.write_raw (http_req, v_raw_content);

It is able to convert itself. What for to suffer, repeating this process.

utl_http.set_body_charset (http_req, ' UTF-8 ');
utl_http.set_header (http_req, ' Transfer-Encoding ', ' chunked ');
utl_http.set_header (http_req, ' Content-Type ', ' text/json; charset=utf-8 ');
utl_http.write_text (http_req, v_content);

13

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

The tired developer;
And the font which developers of it putsreq.com Russian letters use supports?

14

Re: UTL_HTTP To send POST in UTF-8, basis in Win-1251

Elic wrote:

[/code]

It is able to convert itself. What for to suffer, repeating this process.

utl_http.set_body_charset (http_req, ' UTF-8 ');
utl_http.set_header (http_req, ' Transfer-Encoding ', ' chunked ');
utl_http.set_header (http_req, ' Content-Type ', ' text/json; charset=utf-8 ');
utl_http.write_text (http_req, v_content);

Elic, huge human thanks. Earned.