小编Ric*_*ick的帖子

c#httpwebrequest getResponse()冻结并挂起我的程序

我试图使用httpwebrequest在远程服务器上使用类似服务的休息,并且从第一次执行本身开始,我的代码挂起了程序.然后我尝试将它作为控制台应用程序,以确保它与程序本身无关,但没有运气!

        string credentialsJson = @"{""username"":""test"",
                                      ""password"":""test"" 
                                   }";

        int tmp = ServicePointManager.DefaultConnectionLimit;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://qrua.com/qr/service" + @"/auth/login");
        request.Method = "POST";
        request.KeepAlive = true;
        request.Timeout = 50000 ;
        request.CookieContainer = new CookieContainer();
        request.ContentType = "application/json";
        try
        {
            StreamWriter writer = new StreamWriter(request.GetRequestStream());
            writer.Write(credentialsJson);
        }
        catch (Exception e)
        {
            Console.WriteLine("EXCEPTION:" + e.Message);
        }

        //WebResponse response = request.GetResponse();
        try
        {
            using (WebResponse response = (HttpWebResponse)request.GetResponse())
            {
                Console.WriteLine("request:\n" + request.ToString() + "\nresponse:\n" + response.ContentLength);
                response.Close();
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("EXCEPTION: in sending …
Run Code Online (Sandbox Code Playgroud)

c# webrequest httpwebrequest getresponse

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

c# ×1

getresponse ×1

httpwebrequest ×1

webrequest ×1