我正在访问需要自定义协议而不是http中的http的网络服务器。我试图注册我的协议,但没有太多的文件如何让这个工作。 Web服务器提供标准的HTTP响应,但如果请求不是以custom://而不是http://作为前缀,则不起作用。我想直接使用WebRequest底层功能,因为这最终是HTTP,但是,我需要一种方法来使用自定义协议网址提交请求。我注册这样的:使用WebRequest注册自定义协议
WebRequest.RegisterPrefix("custom", new CustomWebRequestCreator());
但后来,当我去创造一个WebRequest的,虽然这个代码后返回我的自定义类:
Uri uri = new Uri("custom://192.168.0.122:94934/resource");
System.Net.WebRequest request = WebRequest.Create(uri);
调试器说,请求实际上我是自定义类,但后来我得到这个异常:
System.NotImplementedException was unhandled
HResult=-2147467263
Message=This method is not implemented by this class.
Source=System
StackTrace:
at System.Net.WebRequest.GetResponse()
...
当我尝试我的网址只是传递对WebRequest.Create()而无需注册前缀,我得到这个异常:
System.NotSupportedException was unhandled
HResult=-2146233067
Message=The URI prefix is not recognized.
Source=System
StackTrace:
at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
at System.Net.WebRequest.Create(Uri requestUri)
...
任何想法我可能会得到这个工作?