【发布时间】:2019-12-20 17:30:41
【问题描述】:
我尝试从我的 C# API 调用自定义协议应用程序。
我的自定义协议已安装,我可以在浏览器中使用“my-app://myParams”URI 调用它, 但我不知道如何使用 webrequest 调用自定义 URL。我尝试添加一个实现 IWebRequestCreate 并调用它的新对象,但我有 stackoverflow 错误。
WebRequest.RegisterPrefix("my-app", new MyCustomWebRequestCreator());
WebRequest req = WebRequest.Create("my-app:");
internal class CustomWebRequestCreator : IWebRequestCreate
{
WebRequest IWebRequestCreate.Create(Uri uri)
{
return WebRequest.Create(uri); // what can I do here ?
}
}
在最后的代码中,我的 WebRequest.Create(uri) 方法出现了 stackoverflow 异常,但我不知道在这个方法中要做什么。
感谢您的帮助
【问题讨论】:
-
I have a stackoverflow exception请向我们展示堆栈。 -
Webrequest.Create 里面没有调用前缀创建者吗?我希望当您注册您的前缀时,这意味着您的处理程序将被调用,并且在您的处理程序中您调用 Webrequest.Create 来调用您的处理程序等。
-
referencesource.microsoft.com/#system/net/system/Net/… 从手机上看不太清楚,但是我认为有在 Create 方法中查找前缀处理程序的逻辑。
-
你做过这个工作吗?
标签: c# custom-protocol