function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
IceEngineIceEngine 

How to Change Charset in XML Document When in Outcall?

Hi,everyone!

    I'm trying to send a http request to a Japanese app, which require the Shift_JIS charset.

    so how to change the charset in the body, and also change here: <?xml version="1.0" encoding="Shift_JIS"?>

    Any help would be much appreciated!
    Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
Jia HuJia Hu
You can try this way,

HttpRequest req= new HttpRequest();
req.setEndpoint('https://xxxxx');
req.setMethod('POST');
req.setHeader('content-type', 'text/xml; charset=Shift_JIS');
......

All Answers

Mike MinakovMike Minakov

If you are using xmlStreamWriter, you can set the encoding at the start of the document like this:

w.writeStartDocument('Shift_JIS', '1.0');

 

Jia HuJia Hu
You can try this way,

HttpRequest req= new HttpRequest();
req.setEndpoint('https://xxxxx');
req.setMethod('POST');
req.setHeader('content-type', 'text/xml; charset=Shift_JIS');
......
This was selected as the best answer
IceEngineIceEngine

Thanks for reply,
when i try this, i would receive an error:

System.XmlException: Underlying stream encoding 'UTF-8' and input paramter for writeStartDocument() method 'Shift_JIS' do not match.

XmlStreamWriter w = new XmlStreamWriter();
w.writeStartDocument('Shift-JIS', '1.0');

 i try UTF-16, the error is the same.

IceEngineIceEngine

Thanks for reply,

it changes the Header to charset=Shift_JIS,

but the body is change too ?

for example, <Node>Text</Node>

it change the node part or the text part, or the whole body?

 

anther question is, if there is a String, how can i change it to Shift_JIS charset?

(i must change string to Shift_JIS and encode to base64, and post the base64 code)

 

Thanks!