ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to URL-ize a string (https://www.excelbanter.com/excel-programming/295491-how-url-ize-string.html)

Bura Tino

How to URL-ize a string
 
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



Robin Hammond[_2_]

How to URL-ize a string
 
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

"Bura Tino" wrote in message
...
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





Tony Morris

How to URL-ize a string
 
"Bura Tino" wrote in message
...
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




Joona I Palaste

How to URL-ize a string
 
Robin Hammond scribbled the following:
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.


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

--
/-- Joona Palaste ) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head

Robin Hammond[_2_]

How to URL-ize a string
 
Thanks for the constructive comment. They work absolutely fine for me using
MSXML2.XMLHTTP40.

Robin Hammond
www.enhanceddatasystems.com

"Joona I Palaste" wrote in message
...
Robin Hammond scribbled the following:
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.


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

--
/-- Joona Palaste ) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head




Bura Tino

How to URL-ize a string
 
"Robin Hammond" wrote in message ...
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?
HTH,

Robin Hammond
www.enhanceddatasystems.com

"Bura Tino" wrote in message
...
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



chris[_13_]

How to URL-ize a string
 
Robin Hammond wrote:

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).

Robin Hammond
www.enhanceddatasystems.com

"Joona I Palaste" wrote in message
...
Robin Hammond scribbled the following:
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.


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

--
/-- Joona Palaste ) ------------- Finland
--------\ \-- http://www.helsinki.fi/~palaste ---------------------
rules! --------/ "It sure is cool having money and chicks."
- Beavis and Butt-head


--
Chris Gray
/k/ Embedded Java Solutions


Chris Smith[_3_]

How to URL-ize a string
 
Robin Hammond wrote:
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

Chris Smith[_3_]

How to URL-ize a string
 
I wrote:
Robin Hammond wrote:
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.


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


All times are GMT +1. The time now is 10:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com