473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Uri with "@" in username

Hello,

I am trying to create a Webrequest. The used Uri is something like
"http://us******@domain.com:pa******@www.shfgshfge.com".
Note that the username contains an "@"-character.
I tried two ways. Neither does work.

1. Directly creating an Uri:

Uri u=new Uri("http://us******@domain.com:pa******@www.shfgshfge.com");

It fails with an System.UriFormatException (Something like "The hostname
cannot be parsed.")
2. Using an UriBuilder:

UriBuilder ub=new UriBuilder();
ub.Host="www.shfgshfge.com";
ub.Scheme="http";
ub.Path="/";
ub.Username="us******@domain.com";
ub.Password="password";

Uri u=ub.Uri;

It fails with the above error.
Unfortunately, the UserInfo property of Uri is readonly.
How can I generate a valid Uri from this string and subsequently use it in a
WebRequest?

TIA

Nov 17 '05 #1
3 18816
Don't know if this will work, but another alternative might be to encode the
@ symbol since it is a special character in the URL. Find out what the code
should be (something like %xx). Also, you might create a dummy webpage that
has a hyperlink with that URL formatted as you want and see how IE sends the
request.

"Hans" <x> wrote in message news:OG**************@TK2MSFTNGP09.phx.gbl...
Hello,

I am trying to create a Webrequest. The used Uri is something like
"http://us******@domain.com:pa******@www.shfgshfge.com".
Note that the username contains an "@"-character.
I tried two ways. Neither does work.

1. Directly creating an Uri:

Uri u=new Uri("http://us******@domain.com:pa******@www.shfgshfge.com");

It fails with an System.UriFormatException (Something like "The
hostname
cannot be parsed.")
2. Using an UriBuilder:

UriBuilder ub=new UriBuilder();
ub.Host="www.shfgshfge.com";
ub.Scheme="http";
ub.Path="/";
ub.Username="us******@domain.com";
ub.Password="password";

Uri u=ub.Uri;

It fails with the above error.
Unfortunately, the UserInfo property of Uri is readonly.
How can I generate a valid Uri from this string and subsequently use it in
a
WebRequest?

TIA

Nov 17 '05 #2
Actually, this is exactly how you would do it. My password in some
places had a @ character in it, so I had to learn the hard way =)
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:eB**************@TK2MSFTNGP14.phx.gbl...
Don't know if this will work, but another alternative might be to encode
the @ symbol since it is a special character in the URL. Find out what
the code should be (something like %xx). Also, you might create a dummy
webpage that has a hyperlink with that URL formatted as you want and see
how IE sends the request.

"Hans" <x> wrote in message news:OG**************@TK2MSFTNGP09.phx.gbl...
Hello,

I am trying to create a Webrequest. The used Uri is something like
"http://us******@domain.com:pa******@www.shfgshfge.com".
Note that the username contains an "@"-character.
I tried two ways. Neither does work.

1. Directly creating an Uri:

Uri u=new
Uri("http://us******@domain.com:pa******@www.shfgshfge.com");

It fails with an System.UriFormatException (Something like "The
hostname
cannot be parsed.")
2. Using an UriBuilder:

UriBuilder ub=new UriBuilder();
ub.Host="www.shfgshfge.com";
ub.Scheme="http";
ub.Path="/";
ub.Username="us******@domain.com";
ub.Password="password";

Uri u=ub.Uri;

It fails with the above error.
Unfortunately, the UserInfo property of Uri is readonly.
How can I generate a valid Uri from this string and subsequently use it
in a
WebRequest?

TIA


Nov 17 '05 #3
Pretty sure you cant pass that form on the url line - if you dig into the
URI spec the syntax is:

[ user [ : password ] @ ] hostport as defined in the wc3 spec for URI's
http://www.w3.org/Addressing/URL/uri-spec.html

The use of the @ is permitted, but only before the host, or within a nntp or
mail address format as URI as it is a reserved character, as defined in
rfc2396
http://www.ietf.org/rfc/rfc2396.txt, so its only going to be accepted where
the RFC permits it to be, and that doesn't appear to be in the username.

Out of interest, does the path work if you type it into a browser?

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Hans" <x> wrote in message news:OG**************@TK2MSFTNGP09.phx.gbl...
Hello,

I am trying to create a Webrequest. The used Uri is something like
"http://us******@domain.com:pa******@www.shfgshfge.com".
Note that the username contains an "@"-character.
I tried two ways. Neither does work.

1. Directly creating an Uri:

Uri u=new Uri("http://us******@domain.com:pa******@www.shfgshfge.com");

It fails with an System.UriFormatException (Something like "The
hostname
cannot be parsed.")
2. Using an UriBuilder:

UriBuilder ub=new UriBuilder();
ub.Host="www.shfgshfge.com";
ub.Scheme="http";
ub.Path="/";
ub.Username="us******@domain.com";
ub.Password="password";

Uri u=ub.Uri;

It fails with the above error.
Unfortunately, the UserInfo property of Uri is readonly.
How can I generate a valid Uri from this string and subsequently use it in
a
WebRequest?

TIA

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
1
by: David Furey | last post by:
Hi I have an XML documnet and a XSLT document as shown below THe XSLT document brings back a filtered docmument that has the VendorName that starts with a particular sub-string This works as...
2
by: Eric Osman | last post by:
Hi, I'm looking for a javascript function that will convert input such as this: <CLUB Code=" into this: &lt;CLUB Code=&quot;
3
by: NecroJoe | last post by:
I am using PHP to generate a little javascript for one of my pages. In short it allows a user to select a value from a list and pop it into a form field on a seperate page. This works well unless...
5
by: Mateusz Loskot | last post by:
Hi, I'd like to ask how XML parsers should handle attributes which consists of &quot; entity as value. I know XML allows to use both: single and double quotes as attribute value terminator. That's...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
5
by: martin | last post by:
Hi, I would be extremly grateful for some help on producing an xml fragemt. The fragment that I wish to produce should look like this <Addresses> <Address>&qout;Somebody's Name&quot;...
8
by: Ulysse | last post by:
Hello, I need to clean the string like this : string = """ bonne mentalit&eacute; mec!:) \n <br>bon pour info moi je suis un serial posteur arceleur dictateur ^^* \n ...
1
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. ...
4
by: fran7 | last post by:
Hi, from help in the javascript forum I found the error in some code but need help. This bit of code works perfectly, trouble is I am writing it to a javascript function so the height needs to be in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.