Questions tagged [urlencode]

To “URL encode” or “percent encode” text means to encode it for use in a URL. Some characters are not valid when used as-is in URLs, and so much be URL-encoded (percent-encoded) when appearing in URLs.

https://url.spec.whatwg.org/#percent-encoded-bytes is the section of the current URL standard that defines percent encoding (URL encoding).

2072 questions
201
votes
17 answers

URLEncoder not able to translate space character

I am expecting System.out.println(java.net.URLEncoder.encode("Hello World", "UTF-8")); to output: Hello%20World (20 is ASCII Hex code for space) However, what I get is: Hello+World Am I using the wrong method? What is the correct method I should be…
Cheok Yan Cheng
  • 49,649
  • 117
  • 410
  • 768
181
votes
6 answers

Server.UrlEncode vs. HttpUtility.UrlEncode

Is there a difference between Server.UrlEncode and HttpUtility.UrlEncode?
Manu
  • 27,156
  • 27
  • 70
  • 82
156
votes
9 answers

JavaScript URL Decode function

What's the best JavaScript URL decode utility? Encoding would be nice too and working well with jQuery is an added bonus.
at.
  • 45,606
  • 92
  • 271
  • 433
150
votes
12 answers

How to create query parameters in Javascript?

Is there any way to create the query parameters for doing a GET request in JavaScript? Just like in Python you have urllib.urlencode(), which takes in a dictionary (or list of two tuples) and creates a string like 'var1=value1&var2=value2'.
cnu
  • 32,169
  • 21
  • 61
  • 63
147
votes
8 answers

How to URL encode a string in Ruby

How do I URI::encode a string like: \x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef\x12\x34\x56\x78\x9a to get it in a format like: %124Vx%9A%BC%DE%F1%23Eg%89%AB%CD%EF%124Vx%9A as per RFC 1738? Here's what I tried: irb(main):123:0>…
HRÓÐÓLFR
  • 5,494
  • 5
  • 30
  • 32
142
votes
13 answers

How to encode a URL in Swift

This is my URL. The problem is, that the address field is not being appended to urlpath. Does anyone know why that is? var address:string address = "American Tourister, Abids Road, Bogulkunta, Hyderabad, Andhra Pradesh, India" let urlpath =…
user3541467
  • 1,543
  • 3
  • 11
  • 6
140
votes
13 answers

Objective-C and Swift URL encoding

I have a NSString like this: http://www. but I want to transform it to: http%3A%2F%2Fwww. How can I do this?
Usi Usi
  • 2,857
  • 5
  • 29
  • 63
138
votes
5 answers

URL Encode and Decode in ASP.NET Core

HttpContext.Current.Server.UrlEncode This does only work in .NET Framework. How can I encode or decode URI arguments in ASP.NET Core?
wtf512
  • 3,357
  • 8
  • 24
  • 44
128
votes
4 answers

Should I URL-encode POST data?

I'm POSTing data to an external API (using PHP, if it's relevant). Should I URL-encode the POST variables that I pass? Or do I only need to URL-encode GET data? UPDATE: This is my PHP, in case it is relevant: $fields = array( …
Richard
  • 26,935
  • 26
  • 98
  • 142
126
votes
6 answers

In a URL, should spaces be encoded using %20 or +?

In a URL, should I encode the spaces using %20 or +? For example, in the following example, which one is correct? www.mydomain.com?type=xbox%20360 www.mydomain.com?type=xbox+360 Our company is leaning to the former, but using the Java method…
MegaByter
  • 1,261
  • 2
  • 8
  • 3
115
votes
7 answers

Encoding URL query parameters in Java

How does one encode query parameters to go on a url in Java? I know, this seems like an obvious and already asked question. There are two subtleties I'm not sure of: Should spaces be encoded on the url as "+" or as "%20"? In chrome if I type in…
Alex Black
  • 12,895
  • 15
  • 73
  • 97
110
votes
5 answers

What is the proper way to URL encode Unicode characters?

I know of the non-standard %uxxxx scheme but that doesn't seem like a wise choice since the scheme has been rejected by the W3C. Some interesting examples: The heart character. If I type this into my browser: http://www.google.com/search?q=♥ Then…
Josh Gibson
  • 18,562
  • 25
  • 62
  • 63
105
votes
5 answers

How to properly URL encode a string in PHP?

I'm making a search page, where you type a search query and the form is submitted to search.php?query=your query. What PHP function is the best and that I should use for encoding/decoding the search query?
Click Upvote
  • 235,452
  • 251
  • 553
  • 736
98
votes
2 answers

Why is curl truncating this query string?

I'm sure the answer to this is going to be some painfully obvious character encoding issue... I'm using curl on the command line to test some endpoints in a python app. The endpoint takes url params of latitude and longitude. Nothing too special. …
DeaconDesperado
  • 8,971
  • 6
  • 43
  • 75
88
votes
3 answers

PHP: convert spaces in string into %20?

How can I convert spaces in string into %20? Here is my attempt: $str = "What happens here?"; echo urlencode($str); The output is "What+happens+here%3F", so the spaces are not represented as %20. What am I doing wrong?
matt
  • 37,699
  • 99
  • 250
  • 390