问题描述
我的一台 Macbook 遇到了最奇怪的问题.我有一个在我的 Macbook 上运行的 C# 应用程序.该应用程序通过 HTTP 与 Web 服务通信,它在我的旧 Macbook 上完美运行.
I am having the weirdest issue on one of my Macbooks. I have a C# application that runs under mono on my Macbook. The application communicates with a web service through HTTP and it works perfectly on my old Macbook.
我买了一台新的 macbook 并正在测试我的应用程序,但出于某种奇怪的原因:
I bought a new macbook and was testing my application but for some weird reason:
HttpWebRequest myReq =
(HttpWebRequest)WebRequest.Create(sURI);
抛出 NotSupportedException
并将提供的 URI 作为异常消息.
Throws NotSupportedException
with the provided URI as the exception message.
我还尝试了以下方法:
HttpWebRequest myReq =
(HttpWebRequest)WebRequest.Create("http://www.google.com");
并得到了同样的例外.我不确定为什么事情会变得疯狂,也想不出任何可能导致这种情况的原因,因为它似乎可以在其他 Mac 上完美运行.
and got the same exception. I'm not sure why things are going crazy and cannot think of anything that could cause this since it seems to work perfectly on other Macs.
我使用的 Mono 版本是 2.10.11
The Mono version I'm using is 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 获取其支持的协议列表,具体来说,配置部分 system.net/webRequestModules代码>.
The WebRequest.GetCreateor gets its list of supported protocols from app.config/machine.config, specifically, the configuration section system.net/webRequestModules
.
如果在那里找不到协议(在您的情况下为http"),它会抛出您的 NotSupportedException.
If the protocol (in your case "http") isn't found there, it throws your NotSupportedException.
所以,请检查您的 machine.config,它可能缺少正确的 webRequestModules.它应该有http"-> HttpRequestCreator.
So, check your machine.config, it's probably missing the correct webRequestModules. It should have "http" -> HttpRequestCreator.
或者,如果一切都失败了,尝试通过反射调用 HttpWebRequest 的私有构造函数.
Or, try calling the private constructor of HttpWebRequest through reflection, if all else fails.
这篇关于单声道下的 WebRequest 不支持 HTTP 协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!