简体   繁体   中英

HttpClient.GetStreamAsync() working on .NET Core and not working on .NET Framework

I have implemented a class which uses HttpClient.GetStreamAsync() method (this class is in a first project). To test my class, I was using a .NET core project (in which i have the main function), and it was working perfectly.

I was asked to use a .NET Framework instead so I created new project (.NET framework) re-used the program.cs of the .NET core project but now when i run the program it is stuck in the HttpClient.GetStreamAsync() method until it reaches a "task was canceled" expectation.

I re-launched the .NET Core project, the method still works

using (StreamReader streamReader = new StreamReader(Client.GetStreamAsync("https://" + User + ".cloudant.com/" + Database + "/_all_docs").Result))
{
    JObject responseContent = (JObject)JToken.ReadFrom(new JsonTextReader(streamReader));
    System.Collections.Generic.KeyValuePair<string, Newtonsoft.Json.Linq.JToken> ids = new KeyValuePair<string, JToken>("", null);
    JToken docsArray = responseContent.GetValue("rows");// type Newtonsoft.Json.Linq.JToken {Newtonsoft.Json.Linq.JArray}

    List<string> IDS = new List<string>();
    foreach (JToken doc in docsArray)
    {
        //Console.WriteLine(doc.ToString());
        string id = doc["id"].Value<string>();
        IDS.Add(id);
    }
    return IDS;
}

所以我尝试了一切可能的方法,我找到了许多解决 GetStreamAsync() 问题的解决方案,但直到一个伙伴告诉我尝试关闭我以前的 StreamReaders 并且繁荣它工作..它正在工作很尴尬.NET Core 而不是 .NET Framework .. streamReader.Close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM