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

How can I percent-encode URL parameters in Python?

Python 2 From the documentation: urllib.quote(string[, safe]) Replace special characters in string using the %xx escape. Letters, digits, and the characters ‘_.-‘ are never quoted. By default, this function is intended for quoting the path section of the URL.The optional safe parameter specifies additional characters that should not be quoted — its default value is … 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

urlencode vs rawurlencode?

It will depend on your purpose. If interoperability with other systems is important then it seems rawurlencode is the way to go. The one exception is legacy systems which expect the query string to follow form-encoding style of spaces encoded as + instead of %20 (in which case you need urlencode). rawurlencode follows RFC 1738 … Read more

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

How to urlencode data for curl command?

Use curl –data-urlencode; from man curl: This posts data, similar to the other –data options with the exception that this performs URL-encoding. To be CGI-compliant, the <data> part should begin with a name followed by a separator and a content specification. Example usage: curl \ –data-urlencode “paramName=value” \ –data-urlencode “secondParam=value” \ http://example.com See the man … Read more

What is %2C in a URL?

Check out http://www.asciitable.com/ Look at the Hx, (Hex) column; 2C maps to , Any unusual encoding can be checked this way +—-+—–+—-+—–+—-+—–+—-+—–+ | Hx | Chr | Hx | Chr | Hx | Chr | Hx | Chr | +—-+—–+—-+—–+—-+—–+—-+—–+ | 00 | NUL | 20 | SPC | 40 | @ | 60 | … Read more

When should space be encoded to plus (+) or %20? [duplicate]

+ means a space only in application/x-www-form-urlencoded content, such as the query part of a URL: http://www.example.com/path/foo+bar/path?query+name=query+value In this URL, the parameter name is query name with a space and the value is query value with a space, but the folder name in the path is literally foo+bar, not foo bar. %20 is a valid … Read more

Query-string encoding of a Javascript Object

like this? serialize = function(obj) { var str = []; for (var p in obj) if (obj.hasOwnProperty(p)) { str.push(encodeURIComponent(p) + “=” + encodeURIComponent(obj[p])); } return str.join(“&”); } console.log(serialize({ foo: “hi there”, bar: “100%” })); // foo=hi%20there&bar=100%25 Edit: this one also converts recursive objects (using php “array” notation for the query string) serialize = function(obj, prefix) … Read more

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(…)

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)