on 2016 Nov 01 12:34 PM
SQL Anywhere 16.0.0.1915
I was so sure this was such a simple thing to do... LOL
I have a database created with no encoding/collation options, so it has the default 1252LATIN1 code page.
I have a simple web service of TYPE RAW. (I am STRINGing data in a JSON format to produce the readable style the consumers of the data would like to receive).
I need to produce output of type UTF-16 or UTF-8.
When I call the web service from a browser, the encoding comes out as Windows-1252.
I have tried RETURNS LONG NVARCHAR and RETURN CSCONVERT(ls_payload, 'UTF-8') but the browser still says I have Windows-1252 encoding.
I have tried CALL sa_set_http_option( 'CharsetConversion', 'On'); to make sure and CALL sa_set_http_option( 'AcceptCharset', 'UTF-8') but the browser still says I have Windows-1252 encoding.
So I am feeling like I must be missing something basic...
Thanks.
Request clarification before answering.
There are several ways to do what you want to do...
The first thing that you are missing is that you are not telling the browser that you are sending it UTF-8 character data. To do this you need to set the Content-Type header. Example:
call sa_set_http_header( 'Content-Type', 'application/json; charset=UTF-8' );
Next you need to make sure that you actually send UTF-8 character data. The easiest (and most easily understood) way is to convert the character data explicitly. Example:
create procedure my_web_proc()
result ( rawdoc long varchar )
begin
declare @result long varchar;
... -- construct your json result
call sa_set_http_header( 'Content-Type', 'application/json; charset=UTF-8' );
call sa_set_http_option( 'CharsetConversion', 'OFF' ); -- tell the server to NOT convert
select csconvert( @result, 'UTF-8' );
end;
The alternative (to setting CharsetConversion to OFF) would be to describe your result set as returning binary - charset conversion is never implicitly done on binary data. Example:
create procedure my_web_proc()
result ( rawdoc long binary )
begin
declare @result long varchar;
... -- construct your json result
call sa_set_http_header( 'Content-Type', 'application/json; charset=UTF-8' );
select csconvert( @result, 'UTF-8' );
end;
HTH
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
30 | |
9 | |
9 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.