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>
seeraigAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

seeraigAuthor Commented:
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.
0
dgrafxCommented:
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 ...
0
James RodgersWeb Applications DeveloperCommented:
have you tried encoding the url values?
URLEncodedFormat(string ,'SHIFT_JIS')

or adding
<cfhttpparam type="HEADER" name="Content-Type" value="charset=shift_jis">
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

seeraigAuthor Commented:
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.
0
James RodgersWeb Applications DeveloperCommented:
cfhttp url encodes by default, the next thing to try is the header encoding, you might need to add text/plaintext to it

<cfhttpparam type="HEADER" name="Content-Type" value="charset=shift_jis">
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
seeraigAuthor Commented:
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">
0
James RodgersWeb Applications DeveloperCommented:
hi sorry for the late response.

yes, that should do it
0
seeraigAuthor Commented:
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')#
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.