facebook error ‘Error validating verification code’

There are presently (as of March 2011) undocumented requirements regarding what makes a valid redirect_uri. First, both redirect_uri paramaters to authorize and access_token must match. Apparently Facebook (or rather OAuth2) is using the redirect_uri as a internal key to encode the code returned for the access_token request. It’s kinda clever since it verifies back to … Read more

URL encoded colon resolves in 400 Bad Request

It seems that ASP.net does not allow colons before the ‘?’ in an URL, even if it is encoded as %3A. For example, these won’t work http://foo.org/api/persons/foo:bar http://foo.org/api/persons/foo%3abar But this works: http://foo.org/api/persons?id=foo%3abar In all examples, we would expect ASP.NET MVC to pass “foo:bar” as an id argument, properly decoded. I just tested this with MVC4 … Read more

String won’t url encode in iOS

For future reference, this is what I found to work (i.e. encode everything properly) + (NSString*)encodeURL:(NSString *)string { NSString *newString = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)string, NULL, CFSTR(“:/?#[]@!$ &'()*+,;=\”<>%{}|\\^~`”), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)); if (newString) { return newString; } return @””; }

Python not able to open file with non-english characters in path

The path in your error is: ‘\xe3\x82\xaf\xe3\x83\xac\xe3\x82\xa4\xe3\x82\xb8\xe3\x83\xbc\xe3\x83\xbb\xe3\x83\x92\xe3\x83\x83\xe3\x83\x84\xef\xbc\x81′ I think this is the UTF8 encoded version of your filename. I’ve created a folder of the same name on Windows7 and placed a file called ‘abc.txt’ in it: >>> a=”\xe3\x82\xaf\xe3\x83\xac\xe3\x82\xa4\xe3\x82\xb8\xe3\x83\xbc\xe3\x83\xbb\xe3\x83\x92\xe3\x83\x83\xe3\x83\x84\xef\xbc\x81″ >>> os.listdir(‘.’) [‘?????\xb7???!’] >>> os.listdir(u’.’) # Pass unicode to have unicode returned to you [u’\u30af\u30ec\u30a4\u30b8\u30fc\u30fb\u30d2\u30c3\u30c4\uff01′] >>> >>> … Read more

On Android, make a POST request with URL Encoded Form data without using UrlEncodedFormEntity

If you don’t mind using an HttpURLConnection instead of the (recommended) HttpClient then you could do it this way: public void performPost(String encodedData) { HttpURLConnection urlc = null; OutputStreamWriter out = null; DataOutputStream dataout = null; BufferedReader in = null; try { URL url = new URL(URL_LOGIN_SUBMIT); urlc = (HttpURLConnection) url.openConnection(); urlc.setRequestMethod(“POST”); urlc.setDoOutput(true); urlc.setDoInput(true); urlc.setUseCaches(false); … Read more

Encode URL query parameters

URLEncoder has a very misleading name. It is according to the Javadocs used encode form parameters using MIME type application/x-www-form-urlencoded. With this said it can be used to encode e.g., query parameters. For instance if a parameter looks like &/?# its encoded equivalent can be used as: String url = “http://host.com/?key=” + URLEncoder.encode(“&/?#”); Unless you … Read more

URL Encode and Decode in ASP.NET Core

For ASP.NET Core 2.0+ just add System.Net namespace – WebUtility class is shipped as part of System.Runtime.Extensions nuget package, that is referenced by default in ASP.NET Core project. For the previous version add Microsoft.AspNetCore.WebUtilities nuget package. Then the WebUtility class will be available for you: public static class WebUtility { public static string UrlDecode(string encodedValue); … Read more