Reputation: 339
I've tried using a few web pages to create QR code to create a QR for a regular url and they fine.
However, if I had parameters to the url, the resulting url does not decode properly.
If you try this
http://chart.apis.google.com/chart?cht=qr&chs=500x500&choe=UTF-8&chld=H&chl=http://localhost?someparam=1&someotherparam=2
instead of the QR code pointing to http://localhost?someparam=1&someotherparam=2
the Barcodescanner decoder apps on Android and iPhone point to
http://localhost/?someparam=1&someotherparam=2
The forward slash / between what would be the server name (domain name) and the start of the parameter string is obviously incorrect.
I'm assuming that it's something to do with url encoding and I'm just looking for a pointer in the right direction from someone who might had already cracked this nut.
Zxing's QR code generator has the same effect. But it seems to rely on Google also.
http://zxing.appspot.com/generator/
Also
http://d-project.googlecode.com/svn/trunk/misc/qrcode/js/sample.html
Upvotes: 2
Views: 11157
Reputation: 14063
You need to URL-encode each parameter value, in your example, the chl
parameter in particular. Most languages have libraries for this these days or a web search for "url encoder " will give you a form.
The url encoding of http://localhost?someparam=1&someotherparam=2
is http%3A%2F%2Flocalhost%3Fsomeparam%3D1%26someotherparam%3D2
.
Also, any parameter values to a URL that is itself a parameter value have to be independently URL encoded as well.
As Sean mentions below, if you enter your URL into the form on the appspot page, it correctly URL encodes the chart url:
http://chart.apis.google.com/chart?cht=qr&chs=350x350&chld=L&choe=UTF-8&chl=http%3A%2F%2Flocalhost%3Fsomeparam%3D1%26someotherparam%3D
I'm not sure about your extra /
comment. If you go to the URL you give, the code value is
http://localhost?someparam=1
which is what is expected because the chl
parameter value is not escaped and therefore ends at the first &
.
Upvotes: 4