WinInet extender and Korean/Japanese characters

Started by DirkM, December 14, 2013, 08:40:53 AM

Previous topic - Next topic

DirkM

Hi there,

I'm currently trying to resolve an issue with Korean and Japanese characters as part of a URL. It's not really a Winbatch issue but at the end I would like to be able to call http://host/upload.asp?FRIENDLY_NAME_V2=Korean/XXX (where XXX is Korean text) with the WinInet extender and the have upload.asp do something with the string later on.

upload.asp is very simple at this time:
<html>
<%   FRIENDLY_NAME_V2=REQUEST("FRIENDLY_NAME_V2") %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>
<body>
<% Response.Write(FRIENDLY_NAME_V2) %>
</body>
</html>

If I open http://host/upload.asp?FRIENDLY_NAME_V2=Korean/XXX with Google Chrome I get Korean/XXX displayed but when I open the url with IE10 then I get Korean/???. I suppose the WinINet extender is using IE dll because whenever I try do this from within WinBatch I get the same as when doing it in IE10.

So my question here is: how can I send Korean text using the WinInet extender to my asp web page (if possible at all)

Thanks,
Dirk

DirkM

Some more details.

I'm currently testing with the following web form:

Code (html5) Select
<html>
<% FRIENDLY_NAME_V2=REQUEST("FRIENDLY_NAME_V2") %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>
<body>
<p><% Response.Write(FRIENDLY_NAME_V2) %></p>
<form method="POST" action="--WEBBOT-SELF--" name="Form1">
<input name="FRIENDLY_NAME_V2" size="70" value="<%Response.Write(FRIENDLY_NAME_V2)%>"/>
<input type="submit" value="Save" name="Submit" style="font-family: Tahoma; font-size: 10pt">
</form>
</body>
</html>


If I enter Korean text in the input field and submit the form then the Korean text is transferred correctly.

Code (winbatch) Select
AddExtender("WWINT44I.DLL")

FriendlyName = ChrHexToUnicode("5CD56DADB4C5") ; this is the Korean text

tophandle=iBegin(0,"","")
WebServerAddr = 'webapp02'
mainurl="/test.asp"
connecthandle=iHostConnect(tophandle, WebServerAddr, @HTTP, '', '')
formdata=""
formdata=iContentUrl(formdata,"FRIENDLY_NAME_V2",FriendlyName)
formdata=iContentUrl(formdata,"submit","Submit")
posturl=strcat(mainurl,"?",formdata)
datahandle=iHttpInit(connecthandle,"POST",posturl,"", 0)
size=10000
buf=BinaryAlloc(size)
bufaddr=IntControl (42, buf, 0, 0, 0)
BinaryEodSet(buf, size)
rslt=iHttpOpen(datahandle, 'Content-Type: text/html; charset=UTF-8', 0,0)
xx=iReadDataBuf(datahandle,bufaddr,size)
rslt=BinaryPeekStr(buf, 0, size)
iClose(datahandle)
iClose(tophandle)
buf=BinaryFree(buf)

Message ('',rslt)

Exit

If I run this Winbatch I only get several ? back. This is the same as calling http://webapp02/test.asp?FRIENDLY_NAME_V2=XXXX where XXXX is some Korean characters.

If I call http://webapp02/test.asp?FRIENDLY_NAME_V2=%ED%95%9C%EA%B5%AD%EC%96%B4 then IE shows the correct Korean characters.

So the main question is: how can I convert the unicode characters to Ansi characters that IE understands?

Any help would be appreciated.

Thanks,
Dirk


DirkM

As always, it's easy once you know what to search for. I found the solution at  http://winbatch.hpdd.de/MyWbtHelp/htm/20100115.HowTo.MakeStringsPortableForTransmitting.htm,  udfStrEncodeURI (strString) does exactly what I needed, encode non-ASCII characters to escaped characters that transmit properly (as far as I can tell).


Code (winbatch) Select
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrEncodeURI (strString)
objSC = CreateObject ("MSScriptControl.ScriptControl")
objSC.Language = "JScript"
Return objSC.Eval(: 'encodeURI("' : StrReplace (strString, '"', '\"') : '")')
;...
; This UDF "udfStrEncodeURI" converts special characters into hexadecimal numbers of format %hex, e. g. " " --> "%20",
; useful for creating "Universal Resource Identifier (URI)" strings.
;
; Characters [a-zA-Z0-9-_.!~*'()] will not be converted.
; Special characters [,/?:@&=+$#] will not be converted (use encodeURIComponent() to encode these characters).
; Some special character will be converted to multibyte UTF-8 character sequence as needed, e. g. "ä" --> "%C3%A4".
; Use the udfStrDecodeURI() function to decode an encoded URI.
;
; Detlev Dalitz.20100116.
...
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------