.NET Core 1.0.0-preview3-004056 MacOSX El Capitan - System.Net.Http.CurlException:无法解析主机名

时间:2016-11-24 14:17:05

标签: .net curl httpclient

我正在运行一个HttpClient" Post"到Oauth2服务来检索令牌。

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)
  

无法解析主机名

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

任何帮助?

由于

1 个答案:

答案 0 :(得分:0)

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

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