Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

Uri class removes double slash

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeroen-bart Engelen - 04 Mar 2006 03:09 GMT
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
Michael Nemtsev - 04 Mar 2006 10:22 GMT
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
Jeroen-bart Engelen - 04 Mar 2006 13:15 GMT
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
Michael Nemtsev - 04 Mar 2006 16:17 GMT
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
Jeroen-bart Engelen - 04 Mar 2006 16:48 GMT
> Hello Jeroen-bart Engelen,
>
[quoted text clipped - 4 lines]
> 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/blabberm
outh.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
Michael Nemtsev - 04 Mar 2006 18:07 GMT
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,
>>
[quoted text clipped - 6 lines]
>> 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
Jeroen-bart Engelen - 05 Mar 2006 15:40 GMT
> 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
Christian Schwendtner - 07 Mar 2006 13:29 GMT
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
Jeroen-bart Engelen - 07 Mar 2006 16:09 GMT
> Hi Jeroen-bart Engelen.
>
[quoted text clipped - 3 lines]
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.