HttpClient在SendAsync(C#)上抛出错误

时间:2013-07-31 11:47:30

标签: windows-8 windows-runtime windows-store-apps exchangewebservices

我的代码(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”。

我的方案是一个应用程序发送肥皂消息来交换Web服务(ews)。

你有什么想法解决我的问题吗?

0 个答案:

没有答案