Link to home
Start Free TrialLog in
Avatar of seeraig
seeraig

asked on

Coldfusion Encoding Issue

I am trying to encode a coldfusion string from UTF-8 encoding to shift_jis. I'm sending a URL string via CFHTTP to a 3rd party that requires the data to be encoded in shift_jis. I'm not very familiar with encoding and the 3rd party is telling me that the data is encoded as UTF-8 and not Shift_JIS. Below is my code with an example URL string I'm posting. I need to know how to properly encode this string, do I have to convert each URL variable from UTF-8 to Shift_JIS? Putting charset="shift_jis" in my CFHTTP tag is not working.

<CFSET ORDER_URL = 'http://xyz.com/CGI/getResponse.aspx?user=123&firstname=¿¿&lastname=¿¿&addr1=¿¿¿¿¿¿¿¿¿28&addr2=&addr3=&city=-&state=¿¿¿&postalcode=787-0026&country=Japan'>

<CFHTTP METHOD="POST" URL="#ORDER_URL#" THROWONERROR="YES" charset="shift_jis">

<cfhttpparam type="header" name="Accept-Encoding" value="*" />
<cfhttpparam type="header" name="TE" value="deflate;q=0" />

</CFHTTP>
Avatar of seeraig
seeraig

ASKER

I'm seeing that experts exchange is not showing my japanese characters correctly in the URL string, perhaps it's my browser character encoding settings.
Avatar of dgrafx
There are different takes on this so I posted some search results:

https://www.google.com/webhp?source=search_app#newwindow=1&q=how+to+encode+japanese+characters+for+a+url 

good luck ...
have you tried encoding the url values?
URLEncodedFormat(string ,'SHIFT_JIS')

or adding
<cfhttpparam type="HEADER" name="Content-Type" value="charset=shift_jis">
Avatar of seeraig

ASKER

I have tried URLEncodedFormat(string ,'SHIFT_JIS'), but that's not what the 3rd party is looking for. This is what they want:

"Can you send me a URL without URLEncoded but all values are encoded in Shift_JIS?"

They want each url variable to be encoded in shift_jis, so "firstname", "lastname", "addr1", "addr2", etc. That is my problem, I don't know how to encode a "string variable" in shift_jis. I know ColdFusion has SetEncoding, but the scope is only form and URL scope variable values. How do I encode just a string variable? PHP has "mb_convert_encoding", so maybe something like that in ColdFusion.

I have not tried <cfhttpparam type="HEADER" name="Content-Type" value="charset=shift_jis">, but not sure if that is the answer. Each individual URL variable needs to be encoded first I think. I can definitely add this to the CFHTTP post though.
ASKER CERTIFIED SOLUTION
Avatar of James Rodgers
James Rodgers
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of seeraig

ASKER

hi jester,

it appears that the content-type header was the problem. the 3rd party put it like this:

<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />

so as far as the cfhttpparam, if i added text/html, would it just be?

<cfhttpparam type="HEADER" name="Content-Type" value="text/html; charset=shift_jis">
hi sorry for the late response.

yes, that should do it
Avatar of seeraig

ASKER

hi,

ok so there was actually more needed for this to work with this 3rd party supplier. This was definitely needed:

<cfhttpparam type="HEADER" name="Content-Type" value="text/html; charset=shift_jis">

but to actually encode each URL string variable correctly as shift_jis, I had to wrap just the URL string values in the URLEncodedFormat and then use the 2nd argument to specify the charset. Here is an example:

http://www.xyz.com?firstname=#URLEncodedFormat('¿¿','shift_jis')#&lastname=#URLEncodedFormat('¿¿','shift_jis')#&addr1=#URLEncodedFormat('¿¿¿¿¿¿5-15-15','shift_jis')#