【问题标题】:.NET Core 1.0.0-preview3-004056 MacOSX El Capitan - System.Net.Http.CurlException: Couldn't resolve host name.NET Core 1.0.0-preview3-004056 MacOSX El Capitan - System.Net.Http.CurlException:无法解析主机名
【发布时间】:2016-11-24 14:17:04
【问题描述】:

我正在向 Oauth2 服务运行 HttpClient“发布”以检索令牌。

var httpClient = new HttpClient(handler);

//HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = tokenRequestBaseUri;

List<KeyValuePair<string, string>> nameValueCollection = new List<KeyValuePair<string, string>>();
nameValueCollection.Add(new KeyValuePair<string, string>("grant_type", "client_credentials"));

System.Net.Http.FormUrlEncodedContent formContent = new FormUrlEncodedContent(nameValueCollection);

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, URIHelper.GetUAATokenRequestRelativeUri());

request.Content = formContent;

string clientId_clientSecret = Convert.ToBase64String(Encoding.UTF8.GetBytes(tenantInformation.ClientId_svcops + ":" + tenantInformation.ClientSecret_svcops));
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", clientId_clientSecret);

logger.Debug("Sending Http Request");

var httpResponseMessage = await httpClient.SendAsync(request);

代码在 Windows 7 上正常运行,但在 MacOSX El Capitan 上的相同代码会引发异常:

System.AggregateException: One or more errors occurred. (An error occurred while sending the request.) ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.CurlException: Couldn't resolve host name
   at System.Net.Http.CurlHandler.ThrowIfCURLEError(CURLcode error)
   at System.Net.Http.CurlHandler.MultiAgent.FinishRequest(StrongToWeakReference`1 easyWrapper, CURLcode messageResult)

无法解析主机名

但如果我打开浏览器,我可以浏览该网址!

有什么帮助吗?

谢谢

【问题讨论】:

  • 可能是 coreClr 中的问题,您应该在 github 上发布问题,而不是在此处发布。 (特别是在使用预览构建版本时)
  • 这已经发布在 Github 上了吗?我遇到了类似的问题。

标签: .net curl httpclient


【解决方案1】:

使用 Visual Studio 2017 RC 和 .NET Core SDK 的 Preview 3 解决了这个问题。

它在 Windows 和 MAC OS 上对齐框架版本。

【讨论】:

    猜你喜欢
    • 2017-05-21
    • 2017-03-26
    • 2017-08-04
    • 1970-01-01
    • 2013-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多