URL encoding in Android

How do you encode a URL in Android? I thought it was like this: final String encodedURL = URLEncoder.encode(urlAsString, “UTF-8”); URL url = new URL(encodedURL); If I do the above, the http:// in urlAsString is replaced by http%3A%2F%2F in encodedURL and then I get a java.net.MalformedURLException when I use the URL. 7 Answers 7

Swift – encode URL

If I encode a string like this: var escapedString = originalString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) it doesn’t escape the slashes /. I’ve searched and found this Objective C code: NSString *encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes( NULL, (CFStringRef)unencodedString, NULL, (CFStringRef)@”!*'();:@&=+$,/?%#[]”, kCFStringEncodingUTF8 ); Is there an easier way to encode an URL and if not, how do I write this in Swift? … Read more

HTTP URL Address Encoding in Java

My Java standalone application gets a URL (which points to a file) from the user and I need to hit it and download it. The problem I am facing is that I am not able to encode the HTTP URL address properly… Example: URL: http://search.barnesandnoble.com/booksearch/first book.pdf java.net.URLEncoder.encode(url.toString(), “ISO-8859-1”); returns me: http%3A%2F%2Fsearch.barnesandnoble.com%2Fbooksearch%2Ffirst+book.pdf But, what I want … Read more