grady
grady

Reputation: 12755

Google QR-Code API encoded URL wrong in .NET and C#

I am using the Google QR-Code API to create a QR-Code that includes a URL. This is the URL I am using:

https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=http://www.test.de/Web/Portale/Form.aspx?PortalId=1&FormName=DetailsForm1&EstateId=14490

What I want in the QR-Code is: http://www.test.de/Web/Portale/Form.aspx?PortalId=1&FormName=DetailsForm1&EstateId=14490

What I get is: http://www.test.de/Web/Portale/Form.aspx?PortalId=1

So its cutting at the "&". Any ideas how to solve that?

Thanks :-)

Upvotes: 1

Views: 2484

Answers (3)

grady
grady

Reputation: 12755

Solved this, the solution was to use the following code:

Server.UrlEncode(string url)

Now it works perfectly :).

Thanks, encoding was what made it click for me :).

Upvotes: 1

You Qi
You Qi

Reputation: 9211

You have to escape for your URL part before parsing into chl parameter.

A simple way would be replacing & with %26 for your url portion.

Try this instead: https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=http://www.test.de/Web/Portale/Form.aspx%3FPortalId=1%26FormName=DetailsForm1%26EstateId=14490

Upvotes: 5

Andy
Andy

Reputation: 9048

You need to URL encode the value of the chl parameter. Otherwise the & in that embedded URL will be interpretted as a delimiter for the parameters in the querystring of the outer googleapis.com URL.

If you are using Javascript you can use encodeURIComponent('http://www.test.de/Web/Portale/Form.aspx?PortalId=1&FormName=DetailsForm1&EstateId=14490') to do the encoding.

Upvotes: 3

Related Questions