我的代码(C#):
HttpClientHandler httpClientHandler = new HttpClientHandler();
httpClientHandler.PreAuthenticate = true;
//httpClientHandler.UseDefaultCredentials = true;
httpClientHandler.Credentials = CredentialCache.DefaultNetworkCredentials;
//httpClientHandler.Credentials = new NetworkCredential("usr", "pw", "domain");
httpClientHandler.CookieContainer = new CookieContainer();
var httpcontent = new StringContent(content);
HttpClient httpClient = new HttpClient(httpClientHandler);
httpClient.DefaultRequestHeaders.ExpectContinue = false;
httpClient.BaseAddress = ews_url;
// var request = httpClient.PostAsync(ews_url, httpcontent);
var requestMessage = new HttpRequestMessage();
requestMessage.RequestUri = ews_url;
requestMessage.Content = httpcontent;
requestMessage.Method = HttpMethod.Post;
var request = httpClient.SendAsync(requestMessage);
HttpResponseMessage response = await request; // --> Error
HttpClient (httpClient) 的实例总是在标有 --> 错误注释的行中遇到异常。我找不到任何错误的代码行。异常说:“底层连接已关闭”,“发送时出错”,但如您所见,连接并未关闭。我尝试了几个选项,例如“UseDefaultCredentials true/false”、“new NetworkCredentials”。
我的场景是一个应用程序发送肥皂消息来交换网络服务(ews)。
你有什么想法可以解决我的问题吗?