帮助 C# HttpWebRequest URI 丢失其编码 [英] Help with C# HttpWebRequest URI losing its encoding

查看:28
本文介绍了帮助 C# HttpWebRequest URI 丢失其编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HttpWebRequest 解码我编码的 URL 时出现问题.

Having a problem with HttpWebRequest decoding my encoded URL.

var requestUrl = "https://www.google.com/webmasters/tools/feeds/http%3A%2F%2Fwww%2example%2Ecom%2F/crawlissues/";   
var request = (HttpWebRequest)WebRequest.Create(requestUrl);

当查看结束请求 URL 时:

When looking at end request URL is becomes:

https://www.google.com/webmasters/tools/feeds/http://www.example.com//crawlissues/

这当然会返回 400 Bad 请求.我猜这与 URI 类而不是 HttpWebRequest 有关.我如何阻止这种情况发生?

Which of course returns a 400 Bad request. I am guessing it is something todo with the URI class rather than HttpWebRequest. How do I stop this from happening?

推荐答案

这是 Uri 类的一个令人讨厌的安全功能".如果您使用的是 4.0 或更高版本,您可以 在你的配置文件中关闭它;否则,你将不得不诉诸反思.

This is an annoying "security feature" of the Uri class. If you're using 4.0 or later, you can turn it off in your configuration file; otherwise, you'll have to resort to reflection.

这篇关于帮助 C# HttpWebRequest URI 丢失其编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆