Why should I use urlencode?

Update: There is an even better explanation (imo) further above: A URI is represented as a sequence of characters, not as a sequence of octets. That is because URI might be “transported” by means that are not through a computer network, e.g., printed on paper, read over the radio, etc. and For original character sequences … Read more

Should I URL-encode POST data?

General Answer The general answer to your question is that it depends. And you get to decide by specifying what your “Content-Type” is in the HTTP headers. A value of “application/x-www-form-urlencoded” means that your POST body will need to be URL encoded just like a GET parameter string. A value of “multipart/form-data” means that you’ll … Read more

How to generate url encoded anchor links with AngularJS?

You can use the native encodeURIComponent in javascript. Also, you can make it into a string filter to utilize it. Here is the example of making escape filter. js: var app = angular.module(‘app’, []); app.filter(‘escape’, function() { return window.encodeURIComponent; }); html: <a ng-href=”#/search?query={{address | escape}}”> (updated: adapting to Karlies’ answer which uses ng-href instead of … Read more

How to encode a URL in Swift [duplicate]

Swift 4.2 var urlString = originalString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) Swift 3.0 var address = “American Tourister, Abids Road, Bogulkunta, Hyderabad, Andhra Pradesh, India” let escapedAddress = address.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) let urlpath = String(format: “http://maps.googleapis.com/maps/api/geocode/json?address=\(escapedAddress)”) Use stringByAddingPercentEncodingWithAllowedCharacters: var escapedAddress = address.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) Use stringByAddingPercentEscapesUsingEncoding: Deprecated in iOS 9 and OS X v10.11 var address = “American Tourister, Abids Road, Bogulkunta, … Read more

Encoding URL query parameters in Java

java.net.URLEncoder.encode(String s, String encoding) can help too. It follows the HTML form encoding application/x-www-form-urlencoded. URLEncoder.encode(query, “UTF-8”); On the other hand, Percent-encoding (also known as URL encoding) encodes space with %20. Colon is a reserved character, so : will still remain a colon, after encoding.

Encode/Decode URLs in C++ [closed]

I faced the encoding half of this problem the other day. Unhappy with the available options, and after taking a look at this C sample code, i decided to roll my own C++ url-encode function: #include <cctype> #include <iomanip> #include <sstream> #include <string> using namespace std; string url_encode(const string &value) { ostringstream escaped; escaped.fill(‘0’); escaped … Read more