Mono下的WebRequest不支持HTTP协议。

8

我在其中一台MacBook上遇到了很奇怪的问题。我有一个在Mono上运行的C#应用程序。该应用程序通过HTTP与Web服务通信,在我的旧MacBook上完美运行。

我买了一台新的Macbook,并测试了我的应用程序,但由于某种奇怪的原因:

    HttpWebRequest myReq =
(HttpWebRequest)WebRequest.Create(sURI);

将提供的URI作为异常消息,抛出NotSupportedException

我还尝试了以下内容:

    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?如果可以,请提供异常的堆栈跟踪。 - jakobandersen
@miracledev,我已经编辑了问题并提供了您所请求的信息。希望它们对您有所帮助。 - Zaid Amir
2个回答

1
WebRequest.GetCreator从app.config/machine.config中获取其支持的协议列表,具体来说是配置部分system.net/webRequestModules。
如果找不到协议(在您的情况下为“http”),它会抛出NotSupportedException。
因此,请检查您的machine.config,可能缺少正确的webRequestModules。它应该有"http" -> HttpRequestCreator。
或者,如果一切都失败了,请尝试通过反射调用HttpWebRequest的私有构造函数。

0

WebRequest.GetCreateor 从 app.config/machine.config 获取其支持的协议列表,具体来说,是配置部分 system.net/webRequestModules。

如果协议(在您的情况下为“http”)在那里找不到,则会抛出 NotSupportedException。

因此,请检查您的 machine.config,可能缺少正确的 webRequestModules。它应该有“http” -> HttpRequestCreator。

或者,如果一切都失败了,请尝试通过反射调用 HttpWebRequest 的私有构造函数。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接