Я занимаюсь разработкой приложения на c #, в котором я загружаю пакет (zip-файл) с сервера. Он загружался правильно, но в последнее время в наших данных пакета произошли некоторые изменения, это гибкое приложение. И с помощью c # мы загружаем его в диск c или диск d.
Теперь с новым пакетом я столкнулся с некоторой проблемой, как
Невозможно прочитать данные из транспортного соединения. Невозможно выполнить операцию с сокетом, поскольку в системе недостаточно места в буфере или очередь заполнена.
Мой код ниже
byte[] packageData = null;
packageData = touchServerClient.DownloadFile("/packages/" + this.PackageName);
public byte[] DownloadFile(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(remoteSite.Url + url);
try
{
request.Method = "GET";
request.KeepAlive = false;
request.CookieContainer = new CookieContainer();
if (this.Cookies != null && this.Cookies.Count > 0)
request.CookieContainer.Add(this.Cookies);
HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();
// Console.WriteLine(response.StatusDescription);
Stream responseStream = webResponse.GetResponseStream();
int contentLength = Convert.ToInt32(webResponse.ContentLength);
byte[] fileData = StreamToByteArray(responseStream, contentLength);
return fileData;
}
public static byte[] StreamToByteArray(Stream stream, int initialLength)
{
// If we've been passed an unhelpful initial length, just
// use 32K.
if (initialLength < 1)
{
initialLength = 32768;
}
byte[] buffer = new byte[initialLength];
int read = 0;
int chunk;
while ((chunk = stream.Read(buffer, read, buffer.Length - read)) > 0)
{
read += chunk;
// If we've reached the end of our buffer, check to see if there's
// any more information
if (read == buffer.Length)
{
int nextByte = stream.ReadByte();
// End of stream? If so, we're done
if (nextByte == -1)
{
return buffer;
}
// Nope. Resize the buffer, put in the byte we've just
// read, and continue
byte[] newBuffer = new byte[buffer.Length * 2];
Array.Copy(buffer, newBuffer, buffer.Length);
newBuffer[read] = (byte)nextByte;
buffer = newBuffer;
read++;
}
}
// Buffer is now too big. Shrink it.
byte[] ret = new byte[read];
Array.Copy(buffer, ret, read);
return ret;
}
В вышеупомянутой функции (StreamToByteArray) я получаю ошибку как
Невозможно прочитать данные из транспортного соединения: не удалось выполнить операцию с сокетом, поскольку в системе не было достаточно буферного пространства или очередь была переполнена.
Пожалуйста, помогите мне в этом, потому что я также не должен менять код.
Спасибо заранее
Шангита