{"id":7556,"date":"2013-06-29T21:00:23","date_gmt":"2013-06-30T02:00:23","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=7556"},"modified":"2013-08-14T14:24:08","modified_gmt":"2013-08-14T19:24:08","slug":"url-encoding","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2013\/06\/29\/url-encoding\/","title":{"rendered":"What Every Web Developer Must Know About URL Encoding"},"content":{"rendered":"<p><a href=\"http:\/\/blog.lunatech.com\/2009\/02\/03\/what-every-web-developer-must-know-about-url-encoding\">St&eacute;phane &Eacute;pardaud<\/a> (via <a href=\"https:\/\/twitter.com\/igrigorik\/status\/351059004283301888\">Ilya Grigorik<\/a>):<\/p>\n<blockquote cite=\"http:\/\/blog.lunatech.com\/2009\/02\/03\/what-every-web-developer-must-know-about-url-encoding\"><p>This article describes common misconceptions about <em>Uniform Resource Locator<\/em> (<a href=\"http:\/\/en.wikipedia.org\/wiki\/URL\">URL<\/a>) encoding, then attempts to clarify <a href=\"http:\/\/en.wikipedia.org\/wiki\/Percent-encoding\">URL encoding<\/a> for <a href=\"http:\/\/en.wikipedia.org\/wiki\/HTTP\">HTTP<\/a>, before presenting frequent problems and their solutions.<\/p><\/blockquote>\n<p>For example:<\/p>\n<blockquote cite=\"http:\/\/blog.lunatech.com\/2009\/02\/03\/what-every-web-developer-must-know-about-url-encoding\"><p>This means that the &ldquo;blue+light blue&rdquo; string has to be encoded differently in the <em>path<\/em> and <em>query<\/em> parts: &ldquo;http:\/\/example.com\/blue+light%20blue?blue%2Blight+blue&rdquo;. From there you can deduce that encoding a fully constructed URL is impossible without a syntactical awareness of the URL structure.<\/p><\/blockquote>\n<p>and:<\/p>\n<blockquote cite=\"http:\/\/blog.lunatech.com\/2009\/02\/03\/what-every-web-developer-must-know-about-url-encoding\"><p>The syntax of the URL is only meaningful <b>before<\/b> it is URL-decoded: after URL-decoding, reserved characters may appear.<\/p><\/blockquote>\n<p>Update (2013-07-13): <a href=\"http:\/\/www.mikeabdullah.net\/escaping-url-paths-in-cocoa.html\">Mike Abdullah<\/a> mentions <a href=\"https:\/\/github.com\/karelia\/KSFileUtilities\/blob\/master\/KSURLComponents.h\">KSURLComponents<\/a>, which can help with this.<\/p>\n<p>Update (2013-07-16): <a href=\"http:\/\/www.mikeabdullah.net\/escaping-url-queries-in-cocoa.html\">Mike Abdullah<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.mikeabdullah.net\/escaping-url-queries-in-cocoa.html\"><p>But what if you want to programmatically construct a URL containing query parameters? Don&rsquo;t worry, I&rsquo;ve got your back again, with <a href=\"https:\/\/github.com\/karelia\/KSFileUtilities\/blob\/master\/KSURLQueryUtilities.h\">KSURLQueryUtilities<\/a>. There you&rsquo;ll find a selection of methods to go between URL (and their strings), and NSDictionary.<\/p><\/blockquote>\n<p>Update (2013-08-14): <a href=\"http:\/\/www.mikeabdullah.net\/escaping-url-hosts-in-cocoa.html\">Mike Abdullah<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.mikeabdullah.net\/escaping-url-hosts-in-cocoa.html\"><p>Most importantly, note the use of : characters in the example above. One is used after the brackets to indicate the port number. But what about this within the brackets? As we saw above, : characters must usually be escaped as part of a hostname, but for literal addresses, the brackets act as an exception to this rule.<\/p>\n<p>[&#8230;]<\/p>\n<p>For further complication, websites can make use of international domain names, whereby characters outside of the regular ASCII set are encoded using a system known as punycode. e.g. the domain&nbsp;<code>ex&auml;mple.com<\/code>&nbsp;is actually addressed as&nbsp;<code>xn--exmple-cua.com<\/code>. Web browsers take care of hiding this detail from users by presenting (and accepting) the unicode form of such domains.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>St&eacute;phane &Eacute;pardaud (via Ilya Grigorik): This article describes common misconceptions about Uniform Resource Locator (URL) encoding, then attempts to clarify URL encoding for HTTP, before presenting frequent problems and their solutions. For example: This means that the &ldquo;blue+light blue&rdquo; string has to be encoded differently in the path and query parts: &ldquo;http:\/\/example.com\/blue+light%20blue?blue%2Blight+blue&rdquo;. From there you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[490,71,258,489,96],"class_list":["post-7556","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-encoding","tag-programming","tag-unicode","tag-url","tag-web"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/7556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=7556"}],"version-history":[{"count":4,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/7556\/revisions"}],"predecessor-version":[{"id":7670,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/7556\/revisions\/7670"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=7556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=7556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=7556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}