Server.URLEncode is making me nuts...... - Posted (1089 Views)
Senior Member
bobby131313
Posts: 1163
1163
I've been googling this for days now, found plenty of people with the same problem but no solutions.
I'm working on a redirection file for my site. One of them is for eBay, the file grabs the query string "eUrl" then encodes it, ads it to the end of another part of the new url then redirects. It works awesome except for ampersands which some eBay urls have.
I've simplified the code so it just displays the output for testing....
Code:

<%
Dim eUrl
eUrl = Server.URLEncode(Request.QueryString("eUrl"))
Response.write (eUrl)
%>

Here's a sample that breaks...
http://www.coincommunity.com/UrlTest.asp?eUrl=http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=330294744298

You'll see that it just stops at the ampersand.
Any ideas?
Thanks!<
 Sort direction, for dates DESC means newest first  
 Page size 
Posted
Posted
Senior Member
bobby131313
Posts: 1163
1163
Sorry I should have explained a little better. This has nothing to do with the forum, it's a completely stand alone file.<
Posted
Average Member
SiSL
Posts: 671
671
You should encode it before you send it to your URLtest.asp

Like you get url , http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=330294744298 right?

Then you encodeURL this... and finally put

http://www.coincommunity.com/UrlTest.asp?eUrl=<encoded url>

If this is done by javascript, you can do it with encodeURIComponent(url)

So in other words, you have to do encoding at script who sends this url to your urltest.asp, not in urltest.asp

if you can't do any modifications, you can simply use trick which may be dangerous if you have other variables...
Like

eURL = Right(Request.QueryString,Len(Request.QueryString)-5)

(5 because of total letters of "eURL=")

<
Posted
Senior Member
bobby131313
Posts: 1163
1163
Now I'm confused. I thought the entire purpose of Server.URLEncode was so I wouldn't have to encode it myself, which is exactly what I'm trying to avoid. Am I wrong?<
Posted
Average Member
SiSL
Posts: 671
671
Ofcourse, but you are UrlEncoding at wrong ASP :)

How would ASP handler be certain if "&view=" is in eURL variable or as another variable? <
Posted
Senior Member
bobby131313
Posts: 1163
1163
Ahhhh... OK, I think I get it now.
It's not the encode fuctions fault, that part of eUrl is left off so it's not even there to encode right?<
Posted
Average Member
SiSL
Posts: 671
671
Posted
Senior Member
bobby131313
Posts: 1163
1163
Thanks for your help, I learned something today. bigsmile<
 
You Must enter a message