c# - 单声道下的 WebRequest 不支持 HTTP 协议(protocol)

标签 c# macos http mono

我的一台 Macbook 遇到了最奇怪的问题。我的 Macbook 上有一个在单声道下运行的 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

问候

最佳答案

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

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

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

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

关于c# - 单声道下的 WebRequest 不支持 HTTP 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17427255/

相关文章:

php - OSX Sierra - 如何正确增加 PHP 内存限制?

rest - 为什么我的请求方法 GET 不受支持?

c# - int + string 怎么变成字符串?

c# - EF 代码优先 - 从代理获取 POCO

c# - SQLite 数据适配器不显示数据

macos - 如何分发 OSX cli/server 应用程序

swift - 使用 macOS 应用程序运送 aws-cli

c# - 出现错误 :Operand type clash: nvarchar is incompatible with image

scala - Play 何时何地设置 Content-Length header ?

java - 如何将对象从android手机发送到servlet?