我正在运行一个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了!
有什么帮助吗?
谢谢
发布于 2016-12-06 13:46:02
使用VisualStudio2017 RC和.NET Core的预览3解决了这个问题。
它使Windows和MAC操作系统上的框架版本一致。
https://stackoverflow.com/questions/40788677
复制相似问题