简体   繁体   English

我可以阻止Uri在WebRequest.Create中取消编码吗?

[英]Can I stop Uri from unencoding a url in WebRequest.Create?

The code itself isn't complex, it's just not working properly: 代码本身并不复杂,它只是不能正常工作:

Uri uri = new Uri("https://www.google.com/webmasters/tools/feeds/sites/http%3A%2F%2Fwww.mydomain.co.uk%2F");
WebRequest.Create(uri);

I get a "Bad Request" back from the server, and after much MUCH digging, discovered that the Uri is being turned into 我从服务器上得到一个“错误请求”,经过多次挖掘,发现Uri正在变成

https://www.google.com/webmasters/tools/feeds/sites/http%3A//www.mydomain.co.uk/ https://www.google.com/webmasters/tools/feeds/sites/http%3A//www.mydomain.co.uk/

which is not what I asked for, and so it's having a whinge 这不是我要求的,所以它有一个旋转

Is there a way to stop this? 有办法阻止这个吗?

Answer found here: https://stackoverflow.com/a/10415482/159341 在此处找到答案: https//stackoverflow.com/a/10415482/159341

According to the bug report for this issue on Microsoft Connect, this behaviour is by design, but you can work around it by adding the following to your app.config or web.config file: 根据Microsoft Connect上此问题的错误报告 ,此行为是设计使然,但您可以通过将以下内容添加到app.config或web.config文件来解决此问题:

<uri>
  <schemeSettings>
    <add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes" />
  </schemeSettings>
</uri>

(Since WebRequest.Create(string) just delegates to WebRequest.Create(Uri), you would need to use this workaround no matter which method you call.) (由于WebRequest.Create(string)只委托给WebRequest.Create(Uri),无论您调用哪种方法,都需要使用此解决方法。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM