Danny Tuppeny
2016-07-22 12:28:29 UTC
(Also on StackOverflow if that's your thing
<http://stackoverflow.com/q/38526408/25124>...)
I wrote some code
<https://blog.dantup.com/2016/07/simplest-csharp-code-to-post-a-tweet-using-oauth/> to
post tweets in C#. One of the things that tripped me up was the
url-encoding of data since there seemed to be many options:
var input = "Hello Ladies + Gentlemen, a signed OAuth request!";var expected = "Hello%20Ladies%20%2B%20Gentlemen%2C%20a%20signed%20OAuth%20request%21";
Console.WriteLine(WebUtility.UrlEncode(input) == expected); // FalseConsole.WriteLine(Uri.EscapeUriString(input) == expected); // FalseConsole.WriteLine(Uri.EscapeDataString(input) == expected); // True
I'm now trying to do the same thing in Dart. I've tried all the encode
methods in the Uri class, but none seem to output the same.
Code: (DartPad
<https://dartpad.dartlang.org/a8874dae0de40be353dace32512becfc>)
print(Uri.encodeQueryComponent("Hello Ladies + Gentlemen, a signed OAuth request!"));
print(Uri.encodeFull("Hello Ladies + Gentlemen, a signed OAuth request!"));
print(Uri.encodeComponent("Hello Ladies + Gentlemen, a signed OAuth request!"));
Output:
Hello+Ladies+%2B+Gentlemen%2C+a+signed+OAuth+request%21Hello%20Ladies%20+%20Gentlemen,%20a%20signed%20OAuth%20request!Hello%20Ladies%20%2B%20Gentlemen%2C%20a%20signed%20OAuth%20request!
The last one (encodeComponent) seems the closest, just the exclamation mark
is wrong.
Is there an existing method that does this encoding as I require (the same
as C#'s EscapeDataString)?
<http://stackoverflow.com/q/38526408/25124>...)
I wrote some code
<https://blog.dantup.com/2016/07/simplest-csharp-code-to-post-a-tweet-using-oauth/> to
post tweets in C#. One of the things that tripped me up was the
url-encoding of data since there seemed to be many options:
var input = "Hello Ladies + Gentlemen, a signed OAuth request!";var expected = "Hello%20Ladies%20%2B%20Gentlemen%2C%20a%20signed%20OAuth%20request%21";
Console.WriteLine(WebUtility.UrlEncode(input) == expected); // FalseConsole.WriteLine(Uri.EscapeUriString(input) == expected); // FalseConsole.WriteLine(Uri.EscapeDataString(input) == expected); // True
I'm now trying to do the same thing in Dart. I've tried all the encode
methods in the Uri class, but none seem to output the same.
Code: (DartPad
<https://dartpad.dartlang.org/a8874dae0de40be353dace32512becfc>)
print(Uri.encodeQueryComponent("Hello Ladies + Gentlemen, a signed OAuth request!"));
print(Uri.encodeFull("Hello Ladies + Gentlemen, a signed OAuth request!"));
print(Uri.encodeComponent("Hello Ladies + Gentlemen, a signed OAuth request!"));
Output:
Hello+Ladies+%2B+Gentlemen%2C+a+signed+OAuth+request%21Hello%20Ladies%20+%20Gentlemen,%20a%20signed%20OAuth%20request!Hello%20Ladies%20%2B%20Gentlemen%2C%20a%20signed%20OAuth%20request!
The last one (encodeComponent) seems the closest, just the exclamation mark
is wrong.
Is there an existing method that does this encoding as I require (the same
as C#'s EscapeDataString)?
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.