我正在使用.net核心,需要对我的服务器执行http调用.
使用的代码如下:
try
{
var client = new HttpClient ();
var helloUri = new System.Uri (string.Concat ("http://localhost:1234", "/hello"));
var response = client.GetAsync (helloUri);
var helloReponse = response.Result;
return helloReponse.StatusCode == System.Net.HttpStatusCode.OK;
}
catch (System.Exception e)
{
throw e;
}
Run Code Online (Sandbox Code Playgroud)
我创建了指定运行时的发布包(在我的例子中是osx10.12-x64).在osx上工作时出现此错误:
(The type initializer for 'System.Net.Http.CurlHandler' threw an
exception.) --->
System.TypeInitializationException: The type
initializer for 'System.Net.Http.CurlHandler' threw an exception. --->
System.TypeInitializationException: The type initializer for 'Http'
threw an exception. --->
System.TypeInitializationException: The type
initializer for 'HttpInitializer' threw an exception. --->
System.TypeInitializationException: …Run Code Online (Sandbox Code Playgroud)