Home All Groups Group Topic Archive Search About

Uri class removes double slash

Author
4 Mar 2006 3:09 AM
Jeroen-bart Engelen
Hello,

I'm currently writing an application that calls a RESTful webservice.
One of the parameters to an  API call is the URL of some site. This
must include the protocol thingy in the beginning. However, the Uri
class *insists* on removing double slashes, so my
"http://somewebsite.com", always becomes "http:/somewebsite.com". Which
does not work for the API I try to call. Is there anyway to get around
this? My main problem is with the WebRequest.Create() function, I guess
it takes the string I provide and creates an Uri object for it's own
use.
Although this behaviour is written in the documentation, this seriously
impacts some webservices and I consider it a bug (bug sounds better
then bad design decision).

Jeroen-bart Engelen

Author
4 Mar 2006 10:22 AM
Michael Nemtsev
Hello Jeroen-bart Engelen,

Use @ sign before your URI like @"http://somewebsite.com"

J> Hello,
J>
J> I'm currently writing an application that calls a RESTful webservice.
J> One of the parameters to an  API call is the URL of some site. This
J> must include the protocol thingy in the beginning. However, the Uri
J> class *insists* on removing double slashes, so my
J> "http://somewebsite.com", always becomes "http:/somewebsite.com".
J> Which
J> does not work for the API I try to call. Is there anyway to get
J> around
J> this? My main problem is with the WebRequest.Create() function, I
J> guess
J> it takes the string I provide and creates an Uri object for it's own
J> use.
J> Although this behaviour is written in the documentation, this
J> seriously
J> impacts some webservices and I consider it a bug (bug sounds better
J> then bad design decision).
J> Jeroen-bart Engelen
J>
---
WBR,
Michael  Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Author
4 Mar 2006 1:15 PM
Jeroen-bart Engelen
Hi, thanks for your reply, but it makes no difference. This isn't the
C-style string escaping (which is the other slash \\), but this is
something the logic of the Uri class does. Just to be sure it did try
it with the @-sign and it didn't work.

Jeroen-bart Engelen
Author
4 Mar 2006 4:17 PM
Michael Nemtsev
Hello Jeroen-bart Engelen,

Could you show your code?

J> Hi, thanks for your reply, but it makes no difference. This isn't the
J> C-style string escaping (which is the other slash \\), but this is
J> something the logic of the Uri class does. Just to be sure it did try
J> it with the @-sign and it didn't work.
J>
J> Jeroen-bart Engelen
J>
---
WBR,
Michael  Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Author
4 Mar 2006 4:48 PM
Jeroen-bart Engelen
Michael Nemtsev wrote:
> Hello Jeroen-bart Engelen,
>
> Could you show your code?
>
> J> Hi, thanks for your reply, but it makes no difference. This isn't the
> J> C-style string escaping (which is the other slash \\), but this is
> J> something the logic of the Uri class does. Just to be sure it did try
> J> it with the @-sign and it didn't work.

using System;
using System.Collections.Generic;
using System.Text;

namespace UriTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri link = new
Uri("http://www.google.com/reader/atom/feed/http://www.roadrunnerrecords.com/blabbermouth.net/newsfeed.xml");
            Console.WriteLine(link.ToString());
        }
    }
}

The console output shows that the second slash for the second "http://"
has been removed, but I need it to be there.

Jeroen-bart Engelen
Author
4 Mar 2006 6:07 PM
Michael Nemtsev
Hello Jeroen-bart Engelen,

It's .NET 2.0 bug parsing to string. in 1.1 it works normal

use Console.WriteLine(link.OriginalString)

J> Michael Nemtsev wrote:
J>
>> Hello Jeroen-bart Engelen,
>>
>> Could you show your code?
>>
>> J> Hi, thanks for your reply, but it makes no difference. This isn't
>> the
>> J> C-style string escaping (which is the other slash \\), but this is
>> J> something the logic of the Uri class does. Just to be sure it did
>> try
>> J> it with the @-sign and it didn't work.
J> using System;
J> using System.Collections.Generic;
J> using System.Text;
J> namespace UriTest
J> {
J> class Program
J> {
J> static void Main(string[] args)
J> {
J> Uri link = new
J> Uri("http://www.google.com/reader/atom/feed/http://www.roadrunnerreco
J> rds.com/blabbermouth.net/newsfeed.xml");
J> Console.WriteLine(link.ToString());
J> }
J> }
J> }
J> The console output shows that the second slash for the second
J> "http://" has been removed, but I need it to be there.
J>
J> Jeroen-bart Engelen
J>
---
WBR,
Michael  Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Author
5 Mar 2006 3:40 PM
Jeroen-bart Engelen
Michael Nemtsev wrote:
> Hello Jeroen-bart Engelen,
>
> It's .NET 2.0 bug parsing to string. in 1.1 it works normal
>
> use Console.WriteLine(link.OriginalString)

I wouldn't call it a bug (I know I did, but it's not really a bug),
because it's documented to work that way, I just want to know a way
around.
If I can use link.OriginalString that I could just as easily use the
string I used to create the Uri to begin with, but the
WebRequest.Create() fucntion takes a Uri or takes a string and uses
that to create a Uri. Which then mangles my request string.

Jeroen-bart Engelen
Author
7 Mar 2006 1:29 PM
Christian Schwendtner
Hi Jeroen-bart Engelen.

Try

Uri link = new
Uri("http://www.google.com/reader/atom/feed/http:/\u2215www.roadrunnerre
cords.com/blabbermouth.net/newsfeed.xml");


hth,
  Chris
Author
7 Mar 2006 4:09 PM
Jeroen-bart Engelen
Christian Schwendtner wrote:
> Hi Jeroen-bart Engelen.
>
> Try
>
> Uri link = new
> Uri("http://www.google.com/reader/atom/feed/http:/\u2215www.roadrunnerre
> cords.com/blabbermouth.net/newsfeed.xml");

Hey...this seems to work. Cool! Thanks!
Unfortunatly I already P/Invoked the hell out of WinInet to write a
class comparable to HttpWebRequest and wrote a simple Uri class, but
I'm going to check if this fix works all the time. Thanks again!

Jeroen-bart Engelen

AddThis Social Bookmark Button