How to urlencode a querystring in Python?

Python 2 What you’re looking for is urllib.quote_plus: safe_string = urllib.quote_plus(‘string_of_characters_like_these:$#@=?%^Q^$’) #Value: ‘string_of_characters_like_these%3A%24%23%40%3D%3F%25%5EQ%5E%24′ Python 3 In Python 3, the urllib package has been broken into smaller components. You’ll use urllib.parse.quote_plus (note the parse child module) import urllib.parse safe_string = urllib.parse.quote_plus(…)

URL Encoding using C#

I’ve been experimenting with the various methods .NET provide for URL encoding. Perhaps the following table will be useful (as output from a test app I wrote): Unencoded UrlEncoded UrlEncodedUnicode UrlPathEncoded EscapedDataString EscapedUriString HtmlEncoded HtmlAttributeEncoded HexEscaped A A A A A A A A %41 B B B B B B B B %42 a … Read more

HTTP URL Address Encoding in Java

The java.net.URI class can help; in the documentation of URL you find Note, the URI class does perform escaping of its component fields in certain circumstances. The recommended way to manage the encoding and decoding of URLs is to use an URI Use one of the constructors with more than one argument, like: URI uri … Read more

URL encoding in Android

You don’t encode the entire URL, only parts of it that come from “unreliable sources”. Java: String query = URLEncoder.encode(“apples oranges”, “utf-8”); String url = “http://stackoverflow.com/search?q=” + query; Kotlin: val query: String = URLEncoder.encode(“apples oranges”, “utf-8”) val url = “http://stackoverflow.com/search?q=$query” Alternatively, you can use Strings.urlEncode(String str) of DroidParts that doesn’t throw checked exceptions. Or use … Read more

Swift – encode URL

Swift 3 In Swift 3 there is addingPercentEncoding let originalString = “test/test” let escapedString = originalString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) print(escapedString!) Output: test%2Ftest Swift 1 In iOS 7 and above there is stringByAddingPercentEncodingWithAllowedCharacters var originalString = “test/test” var escapedString = originalString.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet()) println(“escapedString: \(escapedString)”) Output: test%2Ftest The following are useful (inverted) character sets: URLFragmentAllowedCharacterSet “#%<>[\]^`{|} URLHostAllowedCharacterSet “#%/<>?@\^`{|} URLPasswordAllowedCharacterSet “#%/:<>?@[\]^`{|} … Read more