ErikMrtn Posted March 16, 2018 Share Posted March 16, 2018 Hi everyone! I'm trying to send a string (Filename in Arabic) as a post parameter to PHP using the WinHttp UDF. The problem i'm facing is that, at the server end, the string shows up as "Question Marks" and not in Arabic. However, if i send this string using the Winhttp Objects, it shows up properly in Arabic. Is there any setting in the WinHttp UDF that i need to set before sending the post request, something that would send the post parameter as a UTF-8 string? The request being sent is over SSL, and im using the _WinHttpSimpleSendSSLRequest function. here's the code im using. expandcollapse popup#NoTrayIcon #include<Winhttp.au3> $domain = "someserver.com" $sPath = "/utf-echo.php" Global $ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240" $utfText = "مرحبا بالعالم.docx" $postData = "utf=" & $utfText ;Using Winhttp Object _httpRequestObj("https://" & $domain & $sPath ,'POST', $postData, $ua) ;Using Winhttp UDF $hOpen = _WinHttpOpen($ua) $hConnect = _WinHttpConnect($hOpen, $domain) $hRequest = _WinHttpSimpleSendSSLRequest($hConnect, "POST", $sPath, Default, $postData, Default) Func _httpRequestObj($url, $method, $postData, $ua) $oHTTP = ObjCreate('WinHTTP.WinHTTPRequest.5.1') $method = StringLower($method) Local $oHTTP = ObjCreate('WinHttp.WinHttpRequest.5.1') $oHTTP.Open($method, $url, False) $oHTTP.SetRequestHeader('User-Agent', $ua) $oHTTP.Option(4) = 13056 $oHTTP.Option(9) = 168 If $method = 'GET' Then $oHTTP.Send() Else $oHTTP.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded') $oHTTP.SetRequestHeader('Content-Length', StringLen($postData)) $oHTTP.Send($postData) EndIf $oHTTP.WaitForResponse Local $ret[2] $ret["0"] = $oHTTP.Status $ret["1"] = $oHTTP.Responsetext Return $ret EndFunc ;==>_ProxyhttpRequest Output at the server end: Hope this explains the situation! Any help would be appreciated! thanks!! Link to comment Share on other sites More sharing options...
jchd Posted March 16, 2018 Share Posted March 16, 2018 Convert $postdata (native UTF16-LE string) to UTF8 using _WinAPI_WideCharToMultiByte() This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Zedna Posted March 16, 2018 Share Posted March 16, 2018 (edited) Try to add charset to Content-Type RequestHeader like this (choose apropriate one, utf-16?): $oHTTP.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8') Edited March 16, 2018 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
ErikMrtn Posted March 16, 2018 Author Share Posted March 16, 2018 @jchd Great!, thanks! this worked for me! _WinAPI_WideCharToMultiByte($utfText,65001) Although, i'd still be interested to know how this would work while uploading a file using _WinhttpSimpleFormFill() function from the Winhttp UDF... Any tips? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now