单声道下的 WebRequest 不支持 HTTP 协议
Posted
技术标签:
【中文标题】单声道下的 WebRequest 不支持 HTTP 协议【英文标题】:HTTP protocol not supported in WebRequest under mono 【发布时间】:2013-06-29 22:03:28 【问题描述】:我的一台 Macbook 遇到了最奇怪的问题。我有一个在我的 Macbook 上运行的 C# 应用程序。该应用程序通过 HTTP 与 Web 服务通信,它在我的旧 Macbook 上完美运行。
我买了一台新的 macbook 并正在测试我的应用程序,但出于某种奇怪的原因:
HttpWebRequest myReq =
(HttpWebRequest)WebRequest.Create(sURI);
抛出 NotSupportedException
并将提供的 URI 作为异常消息。
我还尝试了以下方法:
HttpWebRequest myReq =
(HttpWebRequest)WebRequest.Create("http://www.google.com");
并得到了同样的例外。我不确定为什么事情会变得疯狂,也想不出任何可能导致这种情况的原因,因为它似乎可以在其他 Mac 上完美运行。
编辑:
我使用的 Mono 版本是2.10.11
异常的堆栈跟踪是:
Webrequest.Create Exception string : System.NotSupportedException: http://www.google.com/
at System.Net.WebRequest.GetCreator (System.String prefix) [0x00000] in <filename unknown>:0
at System.Net.WebRequest.Create (System.Uri requestUri) [0x00000] in <filename unknown>:0
at System.Net.WebRequest.Create (System.String requestUriString) [0x00000] in <filename unknown>:0
at MyApp.XSPManager.GeneralSOAPFunction (System.String serverName, System.String settingsAsXml, SharedLib.zErrorCodes& errorCode, System.String& message, System.String& actionType) [0x00000] in <filename unknown>:0
问候
【问题讨论】:
你正在运行什么版本的 Mono,并且可能提供异常的堆栈跟踪 @miracledev 我用你要求的信息编辑了这个问题。希望它们有一些价值.. 【参考方案1】:WebRequest.GetCreateor 从 app.config/machine.config 中获取其支持的协议列表,特别是配置部分 system.net/webRequestModules
。
如果在那里找不到协议(在您的情况下为“http”),它会抛出您的 NotSupportedException。
所以,请检查您的 machine.config,它可能缺少正确的 webRequestModules。它应该有“http”-> HttpRequestCreator。
或者,如果一切都失败了,尝试通过反射调用 HttpWebRequest 的私有构造函数。
【讨论】:
以上是关于单声道下的 WebRequest 不支持 HTTP 协议的主要内容,如果未能解决你的问题,请参考以下文章