jeudi 31 mars 2016

C# Encoding URL

My goal is to create a partially encoded uri to create a WebRequest with.

I can encode part of a uri which I can do using HttpUtility.UrlEncode, but then when I create the URI, it decodes it back.

For example

    string urlString = "http://ift.tt/1X15VAM" + HttpUtility.UrlEncode("addr=b@g.com");
    Uri url = new Uri(urlString);

The url is {http://ift.tt/1M4tEzB} but I want http://ift.tt/1M4tEzB

If I pass the urlString to WebRequest.Create(), it does the same thing as seen above.

Does anyone have a solution to this? Either passing a string to WebRequest.Create() or creating a partially encoded URI and passing that to WebRequest.Create() (I'm assuming that a URI passed to WebRequest.Create() doesnt get decoded)




Aucun commentaire:

Enregistrer un commentaire