Alex Gordon
Alex Gordon

Reputation: 60691

what is the purpose of inserting + into a URL instead of space

for example if we have something like this:

http://chart.apis.google.com/chart?chxl=1:|0|10|100|1,000|10,000|100,000|1,000,000|2:||++++++++++++++++++++++++++++++++++++++++++Excretion+in+Nanograms+per+gram+creatinine+milliliter+(logarithmic+scale)|&chxp=1,0|2,0&chxr=0,0,129.8|1,0,3&chxs=0,676767,13.5,0,lt,676767|1,676767,13.5,0,l,676767&chxtc=0,-1000&chxt=y,x,x&chbh=a,1,0&chs=640x465&cht=bvs&chco=A2C180&chds=0,129.8&chd=t:0,0,0,0,1,1,9,24,33,49,64,91,101,112,113,102,116,118,102,94,70,67,44,35,29,28,21,8,8,5,0,5,1,2,3,0,0,1,2,7,4,0,1,3,1,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0&chdl=n=1477&chtt=S.%20Blake%20Kelly,%20MD%20-%20Buprenorphine%20Graph

why not replace all the + with a space? does the browser read the URL differently?

Upvotes: 0

Views: 186

Answers (6)

avpaderno
avpaderno

Reputation: 29669

RFC 1738 reports that spaces are not allowed in a URL. Internet Explorer is notoriously relaxed in its requirements for encoding spaces.

Upvotes: 2

Pete Wilson
Pete Wilson

Reputation: 8694

Plus sign is one of the encodings for space in a URL. The other is %20, which is the hex equivalent of the space character. More to the answer that Slaks gave: it's a real good idea to encode material in the query string. That's the part of the URL you're asking about -- everything after the question mark.

The encoding in this example is incomplete and not too good: the ampersands in "...&chs=640x465&cht=bvs&chco=A2C180&chds=0,129.8&..." and elsewhere should be encoded as '&'

-- b

Upvotes: 0

James Curran
James Curran

Reputation: 103485

Basically, in a HTTP packet, a space indicates the end of the URL.

A typical HTTP request would look like this:

  GET /path/index.htm?id=123 HTTP/1.1

That's all one line with spaces separating the fields, and a CRLF at the end (with more stuff following on the next line).

Upvotes: 2

BoltClock
BoltClock

Reputation: 723388

The + indicates that the space character it represents is significant, because they're not in the URI spec (RFC 1738, section 2.2).

More specifically:

   Characters can be unsafe for a number of reasons.  The space
   character is unsafe because significant spaces may disappear and
   insignificant spaces may be introduced when URLs are transcribed or
   typeset or subjected to the treatment of word-processing programs.

Upvotes: 2

Phil Helix
Phil Helix

Reputation: 3723

I don't fully get what you mean but space decodes as %20 in the address bar '+' is more intuitive - many non-alphanumeric characters are NOT part of any url encoding standard

Upvotes: 1

SLaks
SLaks

Reputation: 887225

The URI format, which is used by the HTTP protocol, does not allow spaces in URLs.

See RFC 2396 section 2.4.3

Upvotes: 5

Related Questions