How to URL-ize a string

B

Bura Tino

Hi,

Sorry for the strange crosspost - I need to solve the same problem in both
environments. I need to pass a string via GET to a script as the value of a
parameter. My string can be arbtrary and so will have spaces, ampersands,
percents, etc. So I need to replace the funny charcters with their %XX
representations. Can I find a ready routine to do this and if not, is there
a list of all substitutions that I need to make?

Thanks!

Bura
 
R

Robin Hammond

Bura,

The spaces should be fine in a Get or Post statement, but you have to watch
out for ampersands and question marks, which precede each parameter
statement. The way I do this is to replace these characters with something
obscure and then Post to an asp page that replaces the obscure characters
with the originals before it does anything else.

HTH,

Robin Hammond
www.enhanceddatasystems.com
 
T

Tony Morris

Bura Tino said:
Hi,

Sorry for the strange crosspost - I need to solve the same problem in both
environments. I need to pass a string via GET to a script as the value of a
parameter. My string can be arbtrary and so will have spaces, ampersands,
percents, etc. So I need to replace the funny charcters with their %XX
representations. Can I find a ready routine to do this and if not, is there
a list of all substitutions that I need to make?

Thanks!

Bura

java.net.URLEncoder surprisingly.

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform
 
J

Joona I Palaste

Robin Hammond said:
The spaces should be fine in a Get or Post statement, but you have to watch
out for ampersands and question marks, which precede each parameter
statement. The way I do this is to replace these characters with something
obscure and then Post to an asp page that replaces the obscure characters
with the originals before it does anything else.

Spaces are *not* fine in a GET or POST statement. They should be
encoded as + or %20.
 
B

Bura Tino

Robin Hammond said:
Bura,

The spaces should be fine in a Get or Post statement, but you have to watch
out for ampersands and question marks, which precede each parameter
statement. The way I do this is to replace these characters with something
obscure and then Post to an asp page that replaces the obscure characters
with the originals before it does anything else.

Thanks. But wouldn't it be better to convert them to, say, %5C and let
the server do the reverse conversions?
 
C

chris

Robin said:
Thanks for the constructive comment. They work absolutely fine for me
using MSXML2.XMLHTTP40.

Whatever that is. They sure aren't valid HTTP; see RFC 2396, section
2.4.3. (RFC 2616, HTTP/1.1, refers to RFC 2396 for the format of a URI).
 
C

Chris Smith

Robin said:
Thanks for the constructive comment. They work absolutely fine for me using
MSXML2.XMLHTTP40.

Perhaps that control does the encoding for you. Or perhaps you've been
lucky and only interacted with servers that are very lax in violating
that specific part of the HTTP specification. In the former case (and
if it's actually documented behavior of the control), then you're fine.
In the latter case, you should really fix this before your code starts
randomly breaking on different servers.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
C

Chris Smith

I said:
Perhaps that control does the encoding for you. Or perhaps you've been
lucky and only interacted with servers that are very lax in violating
that specific part of the HTTP specification. In the former case (and
if it's actually documented behavior of the control), then you're fine.
In the latter case, you should really fix this before your code starts
randomly breaking on different servers.

Okay, I just checked. The documentation for the XMLHTTP control says
that the second parameter to open is a URL, and mentions nothing about
not needing to do encoding for illegal characters. So Robin, I'd
strongly suggest you fix your code.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Robin Hammond

Chris,

thanks for the feedback. Much appreciated that you took the time to research
this. I'll certainly have a look at patching some of my stuff. In terms of
breaking on other servers, thankfully I only use the code to connect to my
own server running IIS and it all runs fine posting to custom asp pages
using the xml control.

Robin Hammond
www.enhanceddatasystems.com
 
R

Roedy Green

Sorry for the strange crosspost - I need to solve the same problem in both
environments. I need to pass a string via GET to a script as the value of a
parameter. My string can be arbtrary and so will have spaces, ampersands,
percents, etc. So I need to replace the funny charcters with their %XX
representations. Can I find a ready routine to do this and if not, is there
a list of all substitutions that I need to make?

see http://mindprod.com/jgloss/printable.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top