单声道下的WebRequest不支持HTTP协议

时间:2013-07-02 13:43:57

标签: c# macos http mono

我在我的一台Macbook上遇到了最棘手的问题。我有一个C#应用程序,在我的Macbook上以mono运行。该应用程序通过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

此致

1 个答案:

答案 0 :(得分:1)

WebRequest.GetCreateor从app.config / machine.config获取支持的协议列表,特别是配置部分system.net/webRequestModules

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

所以,检查你的machine.config,它可能缺少正确的webRequestModules。它应该有“http” - &gt; HttpRequestCreator。

或者,如果所有其他方法都失败,请尝试通过反射调用HttpWebRequest的私有构造函数。