Some characters causing problems in HttpWebRequest

P

Peter Afonin

Hello,

I've created the domain registration system in ASP.NET. I'm using
HttpWebRequest to post the data to the registrar's server. So in the Post
string I'm passing the data like name, address, phone number etc.

The only two fields that are causing problems are the phone and fax fields.
My only guess here is that's because they start with the "+" sign. So the
string looks like this:

strPost=".....&phone=+7 095 2323344&fax=+7 095 7678899&......"

I guess the combination "=+" doesn't work.

The problem is that I must start any phone number with the "+" sign,
otherwise the registrar's system won't accept it. Any substitutes like
Chr(43) do not help here.

Is there a way to deal with this issue? I guess I should be able to pass any
string, but I had no luck so far.

I would greatly appreciate any help.

Thank you,
 
K

Kulgan

You need to URLEncode the parameters. Spaces etc are not permitted in
URLs. You can use:

value = HttpUtility.UrlEncode(value)

to do the necessary conversions.

Kulgan.
 
N

Nicolas Guinet

Hi,

Some characters have special meanings and would cause confusion in a URL
which may result in the data being misinterpreted.
URL encoding is a way of providing a code to represent the textual

Use HttpUtility.UrlEncode( StringToEncode ); to encode data to post

myString = "Name=" + HttpUtility.UrlEncode( "doe" );
myString += "&SurName=" + HttpUtility.UrlEncode( "john" );


Use HttpUtility.UrlDecode( urlToDecode ); to decode data to post


in ASP.net: HttpServerUtility.UrlEncode

String MyURL;
MyURL = "http://www.contoso.com/articles.aspx?title = ASP.NET Examples";
Response.Write( "<A HREF = " + Server.UrlEncode(MyURL) + "> ASP.NET
Examples <br>" );

//NB: MyURL will be encoded as
"http%3a%2f%2fwww.contoso.com%2farticles.aspx%3ftitle+%3d+ASP.NET+Examples"
instead of
"http%3a%2f%2fwww.contoso.com%2farticles.aspx%3ftitle+=+ASP.NET+Examples"

Nicolas Guinet
 
P

Peter Afonin

Hello,

Thank you all very much for your suggestions. I'll try them.

But what would happen with the spaces, for instance, in the address? They
are not allowed. I guess they also will be encoded?

Peter

Nicolas Guinet said:
Hi,

Some characters have special meanings and would cause confusion in a URL
which may result in the data being misinterpreted.
URL encoding is a way of providing a code to represent the textual

Use HttpUtility.UrlEncode( StringToEncode ); to encode data to post

myString = "Name=" + HttpUtility.UrlEncode( "doe" );
myString += "&SurName=" + HttpUtility.UrlEncode( "john" );


Use HttpUtility.UrlDecode( urlToDecode ); to decode data to post


in ASP.net: HttpServerUtility.UrlEncode

String MyURL;
MyURL = "http://www.contoso.com/articles.aspx?title = ASP.NET Examples";
Response.Write( "<A HREF = " + Server.UrlEncode(MyURL) + "> ASP.NET
Examples <br>" );

//NB: MyURL will be encoded as
"http%3a%2f%2fwww.contoso.com%2farticles.aspx%3ftitle+%3d+ASP.NET+Examples"
instead of
"http%3a%2f%2fwww.contoso.com%2farticles.aspx%3ftitle+=+ASP.NET+Examples"

Nicolas Guinet
 
J

Joerg Jooss

Peter said:
Hello,

Thank you all very much for your suggestions. I'll try them.

But what would happen with the spaces, for instance, in the address?
They are not allowed. I guess they also will be encoded?

Sure.

Cheers,
 
Joined
Sep 4, 2007
Messages
1
Reaction score
0
HttpUtility.UrlEncode Does not encode spaces properly

HttpUtility.UrlEncode does not encode spaces properly. It encodes a space as a “+“ which most browsers do not interpret as a space for the obvious reason that + is actually a valid character for a filename

In my application we are downloading file from server in download dialog we want to display full file name. For this we are doint Urlencode for file in response headers like below

Response.AddHeader("Content-Disposition", "attachment; filename=\"" + pageController.Server.UrlEncode(fileName) + fileExtention + "\"");

When we do UrlEncode for file name all space character exists in file name are replacing with + character.
Any idea how can I solve this issue. If anybody knows please help me.

Thanks
Lakshmi Patil
 

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

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top