BrowserWindow.Launch NOT decode string - encoding

In a codedui, this line decodes the link before opening the browser:
myBrowser = BrowserWindow.Launch(New System.Uri("http://blablabla/main.aspx?sn=JFA%3d%3d"))
I want it to remain encoded in the url. In other words, when the browser opens, the %3d are already converted to "=" in the string.
http://mylinkhere/main.aspx?sn=JFA==
I want them to remain as %3d.
Thanks

Try this bro, this is in c# btw.
String URL = HttpUtility.UrlEncode("sn=JFA%3d%3d");
window = BrowserWindow.Launch(new Uri("http://blablabla/main.aspx?" + URL));

Related

How to achieve Base64 URL safe encoding for binary hash string in Powershell?

I am getting the “input” from the server in “Base64-encoded” form as shown in picture.
I need to decode it into its original form of Binary string .i.e original = base64_decode(input) .
concatenate i.e to_be_hash =password (known value) + input.
Hash the concatenated string using SHA-256. i.e binary_hash_str =sha256(to_be_hash).
I need Base64 URL-safe encode the binary hash string above to make it suitable for HTTP requests.
final_hash = base64_url_safe_encode(binary_hash_str)
I am using powershell for this. Can someone guide me how to progress please.
If I understand correctly you would like to send a base64 string as a argument in a url? You can escape the characters that are not acceptable in a url using [uri]::EscapeDataString()
$text = "some text!!"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)
$base64 = [System.Convert]::ToBase64String($bytes)
$urlSafeString = [uri]::EscapeDataString($base64)
"Base64 : " + $base64
"urlSafeString : " + $urlSafeString
Base64 : cwBvAG0AZQAgAHQAZQB4AHQAIQAhAA==
urlSafeString : cwBvAG0AZQAgAHQAZQB4AHQAIQAhAA%3D%3D

How to display Unicode Smiley from json response dynamically in flutter

How to display Unicode Smiley from json response dynamically in flutter. It's display properly when i declare string as a static but from dynamic response it's not display smiley properly.
Static Declaration: (Working)
child: Text("\ud83d\ude0e\ud83d\ude0eThis is just test notification..\ud83d\ude0e\ud83d\ude0e\ud83d\udcaf\ud83d\ude4c")
Dynamic Response:
"message":"\\ud83d\\ude4c Be Safe at your home \\ud83c\\udfe0",
When i'm parse and pass this response to Text then it's consider Unicode as a String and display as a string instead of Smiley Code is below to display text with smiley:
child: Text(_listData[index].message.toString().replaceAll("\\\\", "\\"))
Already go through this: Question but it's only working when single unicode not working with multiple unicode.
Anyone worked with text along with unicode caracter display dynamically then please let me know.
Another alternate Good Solution I would give to unescape characters is this:
1st ->
String s = "\\ud83d\\ude0e Be Safe at your home \\ud83c\\ude0e";
String q = s.replaceAll("\\\\", "\\");
This would print and wont be able to escape characters:
\ud83d\ud83d Be Safe at your home \ud83c\ud83d
and above would be the output.
So what one can do is either unescape them while parsing or use:
String convertStringToUnicode(String content) {
String regex = "\\u";
int offset = content.indexOf(regex) + regex.length;
while(offset > 1){
int limit = offset + 4;
String str = content.substring(offset, limit);
// print(str);
if(str!=null && str.isNotEmpty){
String uni = String.fromCharCode(int.parse(str,radix:16));
content = content.replaceFirst(regex+str,uni);
// print(content);
}
offset = content.indexOf(regex) + regex.length;
// print(offset);
}
return content;
}
This will replace and convert all the literals into unicode characters and result and output of emoji:
String k = convertStringToUnicode(q);
print(k);
😎 Be Safe at your home 🈎
That is above would be the output.
Note: above answer given would just work as good but this is just when you want to have an unescape function and don't need to use third-party libraries.
You can extend this using switch cases with multiple unescape solutions.
Issue resolved by using below code snippet.
Client client = Client();
final response = await client.get(Uri.parse('YOUR_API_URL'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
final extractedData = json.decode(response.body.replaceAll("\\\\", "\\"));
}
Here we need to replace double backslash to single backslash and then decode JSON respone before set into Text like this we can display multiple unicode like this:
final extractedData = json.decode(response.body.replaceAll("\\",
"\"));
Hope this answer help to other

ASP ANSI Conversion for Unicode Based Text File

I have these ASP script for cache
fn = "caches/"&md5(url)&".html"
// Grab HTML file from site
set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")
oXMLHTTP.Open "GET", url, false
oXMLHTTP.Send
// Save it
set fs = Server.CreateObject("Scripting.FileSystemObject")
set file = fs.CreateTextfile(fn,false,true)
file.Write oXMLHTTP.responseText
file.close
// Open it and print to screen
set file = fs.OpenTextFile(fn,1)
response.write file.ReadAll
file.Close
response.end
Saved files are "Unicode BOM" encoded, and this causes char problems. When I am convert encoding to "ANSI", everything becomes look normal as expected.
How to covert "oXMLHTTP.responseText" to "ANSI" programaticly?
Best practice is saving binary instead of text always. You can access response binary by using oXMLHTTP.responseBody instead.
However, if you are sure that the response text is compatible with your locale, it is safe to save the response text in ANSI with no problem.
To do this, you need to pass False for third parameter of CreateTextFile method.
set file = fs.CreateTextfile(fn, false, false)
But I strongly recommend you to save the binary like the following:
Dim Stm
Set Stm = Server.CreateObject("Adodb.Stream")
Stm.Type = 1 'adTypeBinary, to set binary stream
Stm.Open
Stm.Write oXMLHTTP.responseBody ' bytes of http response
Stm.SaveToFile fn 'response saved as is
Stm.Close
Set Stm = Nothing

Encoding URLs containing unicode characters

Is there an Android class that (correctly) encodes URLs containing unicode characters? For example:
Blue Öyster Cult
Is converted to the following using java.net.URI:
uri.toString()
(java.lang.String) Blue%20Öyster%20Cult
The Ö character is not encoded. Using URLEncoder:
URLEncoder.encode("Blue Öyster Cult", "UTF-8").toString()
(java.lang.String) Blue+%C3%96yster+Cult
It encodes too much (i.e. spaces become "+" and path separators "/" become %2F). If I click on a link containing unicode characters with the Dolphin web browser it works correctly, so obviously this can be done. But if I try to open an HttpURLConnection using any of the above strings, I get an HTTP 404 Not Found exception.
I ended up hacking together a solution that seems to work for this, but is probably not the most robust:
url = new URL(userSuppliedPath);
String context = url.getProtocol();
String hostname = url.getHost();
String thePath = url.getPath();
int port = url.getPort();
thePath = thePath.replaceAll("(^/|/$)", ""); // removes beginning/end slash
String encodedPath = URLEncoder.encode(thePath, "UTF-8"); // encodes unicode characters
encodedPath = encodedPath.replace("+", "%20"); // change + to %20 (space)
encodedPath = encodedPath.replace("%2F", "/"); // change %2F back to slash
urlString = context + "://" + hostname + ":" + port + "/" + encodedPath;
URLEncoder is designed to be used to encode form content, not whole URI's. Encoding / as %2F is intentional to prevent user input from being interpreted as a directory, and + is valid encoding for form data. (form data == part of the URI following the ?)
Ideally, you would encode "Blue Öyster Cult" before appending it to your base URI, instead of encoding the whole string. And if "Blue Öyster Cult" is part of the path instead of part of the query string, you have to replace + with %20 yourself. With these restrictions, URLEncoder works fine.

Method post: accents on my app's description, posting on user's wall, result in diamonds and interrogation signs

I'm using a http call to post information about my app in any user's wall. I do it in this way:
_url = "https://graph.facebook.com/" + user_id + "/feed?message=MSG";
_url += "&access_token=" + access_token;
_url += "&picture=" + fb_app_url + "fb_icon.png";
_url += "&name=" + String_ToUrl("MY GAMES");
_url += "&link=" + "http://www.nlkgames.com";
_url += "&description=String_ToUrl("descripción with accent")"
_url += "&method=post";
http.URL_CALL(_url);
This method post right the information in the user's wall, but the accents are shown by a diamond with a question sign inside it. I don't know how to make it works with accents.
String_ToUrl will encode string in this way:
"descripción with accent" = "descripci%E9n+with+accent"
What's my fail? Why the user's facebook's wall doesn't recognize the urlencoded?
Instead of encoding it for URL, what happens if you just post the description as is?
If that doesn't work, try converting the string using HTML entities and then URL Encoding the description.
you could also try to replace those letters with the ASCII representation (somewhat like \u123) - that would be what the Graph API gives you when there is such a Special character (in my case it would be äöü from the german alphabet)
Your String_ToUrl function doesn't encode URL in unicode aware way.
ó (aka 'LATIN SMALL LETTER O WITH ACUTE' (U+00F3)) should became %C3%B3 in URL encoded form, and not %F3 (in your case you indicated that it became %E9 which in fact é character).
descripción -> descripci%C3%B3n
Be sure to use proper (and unicode aware) way to encode your parameters, in JavaScript for example encodeURIComponent should be used...