Как использовать restful service в настольном приложении
мы получили ошибку ниже
Базовое соединение было закрыто: произошла непредвиденная ошибка при приеме.
Что я уже пробовал:
var request = (HttpWebRequest)WebRequest.Create(EndPoint); request.Method = Method; request.ContentLength = 0; request.ContentType = contentType; request.Timeout = 600000; request.KeepAlive = false; request.UseDefaultCredentials = true; request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials; request.Method = WebRequestMethods.Http.Post.ToString(); request.Credentials = new NetworkCredential(username, password); if (Method == "POST") { object input = new { firstName = "a", LastName = "b", }; string inputJson = (new JavaScriptSerializer()).Serialize(input); byte[] bytes = System.Text.Encoding.ASCII.GetBytes(inputJson); request.ContentLength = bytes.Length; System.IO.Stream os = request.GetRequestStream(); os.Write(bytes, 0, bytes.Length); os.Close(); } using (var response = (HttpWebResponse)request.GetResponse())// request.address changes at this line on "POST" method types { var responseValue = string.Empty; if (response.StatusCode != HttpStatusCode.OK) { var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode); throw new ApplicationException(message); } // grab the response using (var responseStream = response.GetResponseStream()) { if (responseStream != null) using (var reader = new StreamReader(responseStream)) { responseValue = reader.ReadToEnd(); } } return responseValue; }