Why does this code hang on reaching the first ReadLine from a StreamReader?

后端 未结 1 750
悲&欢浪女
悲&欢浪女 2021-01-29 16:51

I was passing a large file in the first arg to SendXMLFile() below but, since it was causing the handheld device to \"hang\"/\"freeze\" I temporarily hard-coded a much smaller f

1条回答
  •  迷失自我
    2021-01-29 17:07

    I think you should return to basics:

    public static string SendXMLFile(string xmlFilepath, string uri, int timeout)
    {
        using (var client = new WebClient())
        {                
            client.Headers.Add("Content-Type", "application/xml");                
            byte[] response = client.UploadFile(uri, "POST", xmlFilepath);
            return Encoding.ASCII.GetString(response);
        }
    }
    

    and see what works and what the server thinks of your file.

    When you really need a TimeOut then see this answer

    0 讨论(0)
提交回复
热议问题