首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.NET Core1.0.0-预览3-004056 MacOSX El Capitan - System.Net.Http.CurlException:无法解析主机名

.NET Core1.0.0-预览3-004056 MacOSX El Capitan - System.Net.Http.CurlException:无法解析主机名
EN

Stack Overflow用户
提问于 2016-11-24 14:17:04
回答 1查看 360关注 0票数 1

我正在运行一个HttpClient "Post“到一个Oauth2服务,以收回一个令牌。

代码语言:javascript
复制
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上的相同代码会抛出异常:

代码语言:javascript
复制
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了!

有什么帮助吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-06 13:46:02

使用VisualStudio2017 RC和.NET Core的预览3解决了这个问题。

它使Windows和MAC操作系统上的框架版本一致。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40788677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档