rot3r Posted February 22, 2022 Posted February 22, 2022 (edited) Hi friends, I'm using json.au3 to register some data in my server, everything work fine except the data that i send in utf8 format like names saved as ????? . i think something mess with inetget cause this problem can you help me please? $sAdditionalData = "secret_key=" & $secret_key_verify & "&slm_action=slm_check&license_key=" & $license_key&"&first_name="&$first_name $data = _INetGetSource($sDomain&'/?'&$sAdditionalData) $object = json_decode($data) Json_Dump($data) $response = json_get($object, '.first_name') Edited February 22, 2022 by rot3r
Danp2 Posted February 22, 2022 Posted February 22, 2022 Can you post the JSON string contained in $data? Latest Webdriver UDF Release Webdriver Wiki FAQs
rot3r Posted February 22, 2022 Author Posted February 22, 2022 its $sAdditionalData (the first_name output is correctly shown ) its $data output (the first name field changed to ???????)
Danp2 Posted February 22, 2022 Posted February 22, 2022 Please capture the data and post it as text instead of an image. That will allow others to help you with this issue. Also, please do the same but with the following modification -- $data = _INetGetSource($sDomain&'/?'&$sAdditionalData, False) Latest Webdriver UDF Release Webdriver Wiki FAQs
Solution TheXman Posted February 22, 2022 Solution Posted February 22, 2022 (edited) Most browsers will try to properly encode a URL before sending it. As you have found out, the _InetGetSource() function does not do any special encoding of your URL. Therefore, you must make sure that your URL is properly encoded before sending it. The example below shows one of many functions (_UnicodeURLEncode) that can be used to encode all or part of a URL. You can find another example in the topic below. If you are building URLs dynamically, it's probably a good idea to encode the URL whether you think you need to or not. Example: expandcollapse popup#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #include <Constants.au3> #include <Inet.au3> #include <Debug.au3> #include <json.au3> example() Func example() Local $sEncodedRequest, $sRespone, $sJson Local $oJson Const $REQUEST = "https://postman-echo.com/get?first_name=سلام" _DebugSetup(Default, False, 5) ;Encode & display the URL $sEncodedRequest = _UnicodeURLEncode("https://postman-echo.com/get?first_name=سلام") _DebugOut("HTTP Request (Raw) = " & $REQUEST) _DebugOut("HTTP Request (Encoded) = " & $sEncodedRequest) ;Send HTTP GET request $sRespone = _INetGetSource($sEncodedRequest, False) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "_INetGetSource failed! @error = " & @error) ;Decode JSON response $oJson = Json_Decode(BinaryToString($sRespone, $SB_UTF8)) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Unable to decode response. @error = " & @error) ;Display pretty-printed response (unicode and slashes are unescaped) $sJson = Json_Encode($oJson, $JSON_PRETTY_PRINT + $JSON_UNESCAPED_UNICODE + $JSON_UNESCAPED_SLASHES, " ") _DebugOut(@CRLF & "JSON Response (unicode and slashes are unescaped)") _DebugOut($sJson) EndFunc ;=============================================================================== ; _UnicodeURLEncode() ; Description: : Encodes an unicode string to be URL-friendly ; Parameter(s): : $UnicodeURL - The Unicode String to Encode ; Return Value(s): : The URL encoded string ; Author(s): : Dhilip89 ; Note(s): ; https://www.autoitscript.com/forum/topic/46894-unicodeurl-udf/ ;=============================================================================== Func _UnicodeURLEncode($UnicodeURL) Local $UnicodeBinary = StringToBinary ($UnicodeURL, 4) Local $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1) Local $UnicodeBinaryLength = StringLen($UnicodeBinary2) Local $UnicodeBinaryChar Local $EncodedString For $i = 1 To $UnicodeBinaryLength Step 2 $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2) If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString ('0x' & $UnicodeBinaryChar, 4)) Then $EncodedString &= BinaryToString ('0x' & $UnicodeBinaryChar) Else $EncodedString &= '%' & $UnicodeBinaryChar EndIf Next Return $EncodedString EndFunc Example output HTTP Request (Raw) = https://postman-echo.com/get?first_name=سلام HTTP Request (Encoded) = https://postman-echo.com/get?first_name=%D8%B3%D9%84%D8%A7%D9%85 JSON Response (unicode and slashes are unescaped) { "args": { "first_name": "سلام" }, "headers": { "x-forwarded-proto": "https", "x-forwarded-port": "443", "host": "postman-echo.com", "x-amzn-trace-id": "Root=1-6215610f-575e35fb5529a4b26d20bf55", "user-agent": "AutoIt", "cache-control": "no-cache" }, "url": "https://postman-echo.com/get?first_name=%D8%B3%D9%84%D8%A7%D9%85" } Edited February 22, 2022 by TheXman rot3r 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
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