nullschritt Posted September 8, 2012 Share Posted September 8, 2012 (edited) I was just wondering how I would go about encoding a string for http transport (encoding the special characters like "#$%&=", etc?) Thanks Edited September 9, 2012 by nullschritt Link to comment Share on other sites More sharing options...
dany Posted September 8, 2012 Share Posted September 8, 2012 Do a search on base64 encoding. [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF Link to comment Share on other sites More sharing options...
nullschritt Posted September 8, 2012 Author Share Posted September 8, 2012 Do a search on base64 encoding.I don't want to encode the whole string just special characters. Link to comment Share on other sites More sharing options...
dany Posted September 8, 2012 Share Posted September 8, 2012 (edited) Then you'll have to make up your own identifiers like __AMPERSAND__ or something and do some string replacing on both ends.edit: Wait I forgot about url encoding, still same priciple with string replacing. Edited September 9, 2012 by dany [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF Link to comment Share on other sites More sharing options...
nullschritt Posted September 9, 2012 Author Share Posted September 9, 2012 (edited) My solution: (not tested yet, going to test later) In case anyone else was wondering the same thing func _urlencode($string) $string = StringSplit($string, "") for $i=1 to $string[0] If chrw($string[$i]) < 48 or chrw($string[$i]) > 122 $string[$i] = "%"&_StringToHex($string[$i]) EndIf Next $string = _ArrayToString($string, "") Return $string EndFunc func _urldecode($string) $string = StringSplit($string, "%") for $i=1 to $string[0] $string[$i] = _HexToString(StringLeft($string[$i], 2))&StringTrimLeft($string[$i], 2) Next $string = _ArrayToString($string, "") Return $string EndFunc Edited September 9, 2012 by nullschritt Link to comment Share on other sites More sharing options...
dany Posted September 9, 2012 Share Posted September 9, 2012 (edited) Almost You used ChrW where AscW is needed and forgot a string check for hexadecimals. Fixed below. Do a forum search on 'urlencode', you'll get some pretty interresting topics. #include <String.au3> #include <Array.au3> Func _urlencode($string) $string = StringSplit($string, "") For $i=1 To $string[0] If AscW($string[$i]) < 48 Or AscW($string[$i]) > 122 Then $string[$i] = "%"&_StringToHex($string[$i]) EndIf Next $string = _ArrayToString($string, "", 1) Return $string EndFunc Func _urldecode($string) $string = StringSplit($string, "%") For $i=1 To $string[0] If StringIsXDigit(StringLeft($string[$i], 2)) Then ; Otherwise you get stray 0x in the string. $string[$i] = _HexToString(StringLeft($string[$i], 2))&StringTrimLeft($string[$i], 2) EndIf Next $string = _ArrayToString($string, "", 1) Return $string EndFunc ; Using w3school example. Local $sUrl = 'Hello Günter' Local $sEnc = _urlencode($sUrl) MsgBox(0, '', $sEnc) Local $sDec = _urldecode($sEnc) MsgBox(0, '', $sDec) Edited September 9, 2012 by dany [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF Link to comment Share on other sites More sharing options...
ProgAndy Posted September 9, 2012 Share Posted September 9, 2012 Here is my take on the functions *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes 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