Pickels
Pickels

Reputation: 34690

Query string: Can a query string contain a URL that also contains query strings?

Example:

http://foo.com/generatepdf.aspx?u=http://foo.com/somepage.aspx?color=blue&size=15

I added the iis tag because I am guessing it also depends on what server technology you use?

Upvotes: 7

Views: 3934

Answers (5)

Marco
Marco

Reputation: 75

As reported in http://en.wikipedia.org/wiki/Query_string

W3C recommends that all web servers support semicolon separators in addition to ampersand separators (link reported on that wiki page) to allow application/x-www-form-urlencoded query strings in URLs within HTML documents without having to entity escape ampersands.

So, I suppose the answer to the question is yes and you have to change in a ";" semicolon the "&" ampersand usaully used for key=value separator.

Upvotes: 1

KajMagnus
KajMagnus

Reputation: 11696

Yes it can, as far as I can tell, according to RFC 3986: Uniform Resource Identifier (URI): Generic Syntax (from year 2005):

This is the BNF for the query string:

query         = *( pchar / "/" / "?" )
pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"

The spec says:

  • The characters slash ("/") and question mark ("?") may represent data within the query component.
  • as query components are often used to carry identifying information in the form of "key=value" pairs and one frequently used value is a reference to another URI, it is sometimes better for usability to avoid percent-encoding those characters

(But I suppose your server framework might or might not follow the specification exactly.)

Upvotes: 0

zzzzBov
zzzzBov

Reputation: 179284

The server technology shouldn't make a difference.

When you pass a value to a query string you need to url encode the name/value pair. If you want to pass in a value that contains a special character such as a question mark (?) you'll just need to encode that character as %3F. If you then needed to recursively pass another query string to the encoded url, you'll need to double/triple/etc encode the url resulting in the original ? turning into %253F, %25253F, etc.

Upvotes: 3

Lucas Moeskops
Lucas Moeskops

Reputation: 5443

No, but you can encode the url and decode it later.

Upvotes: -1

John Boker
John Boker

Reputation: 83729

you'll probably want to UrlEncode the url that is in the query string.

Upvotes: 2

Related Questions