c# - How to make request with encoded URL in .NET 4.5+? -


today encountered interesting problem. following code doesn't work correctly.

public static void main()   {   string html;   var requesturi = new uri("https://en.wikipedia.org/wiki/c%c3%b4te_d%27ivoire");   var httpwebrequest = (httpwebrequest)webrequest.create(requesturi);   using (var httpwebresponse = (httpwebresponse)httpwebrequest.getresponse())     {     using (stream responsestream = httpwebresponse.getresponsestream())       {       string characterset = httpwebresponse.characterset;       using (var streamreader = new streamreader(responsestream, characterset != null ? encoding.getencoding(characterset) : encoding.utf8))         {         html = streamreader.readtoend();         }       }     }   } 

the problem in url decoding. in uri constructor original string automatically decoded , result "https://en.wikipedia.org/wiki/côte_d'ivoire". requesting url results in 304 location "https://en.wikipedia.org/wiki/c%c3%b4te_d%27ivoire", original encoded url, , causes infinite loop.


what should do? this configuation doesn't cause allows ignore dots , slashes.

for example, fiddler works fine in situation. requesting "https://en.wikipedia.org/wiki/côte_d'ivoire" results in 1 redirect.

enter image description here


update

it works in .net 4.0.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -