У меня есть клиентское приложение, работающее на C # на устройстве .NETCF 3.5, размещаемое в сервлете Java, расположенном удаленно. Я получаю «Тайм-аут запроса» во время моего третьего HTTP POST к тому же сервлету. Например, если сервлет управляет входом в систему на нашем Java-сервере, первые две попытки входа в систему от клиента будут выполнены (то же самое клиентское устройство), а когда я попытаюсь выполнить третье, он вернется в исключении «Запрос истек тайм-аут» из сервер. Я заметил, что это происходит всегда, и я не могу понять проблему. Я прочитал, что C # по умолчанию отправляет запрос 100 продолжить в заголовках HTTP, поэтому я использовал ServicePointManager, чтобы установить для запроса 100 значение false, но безрезультатно.
Вот код, который выдает эту ошибку:
serverUrl = url;
string responseFromServer = "";
try
{
System.Net.ServicePointManager.Expect100Continue = false;
int tmp = ServicePointManager.DefaultConnectionLimit;
// Create a request using a URL that can receive a post.
request = (HttpWebRequest)WebRequest.Create(url);
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(url);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
request.Timeout = (50 * 100);
request.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy();
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
response = (HttpWebResponse)request.GetResponse();
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
responseFromServer = reader.ReadToEnd();
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
return responseFromServer;
}
catch (Exception WebExp)
{
Logging.Instance.Log(Logging.Levels.Error, "Error in DoPost while retrieving : "+url+ " " + WebExp.Message.ToString());
Logging.Instance.Log(Logging.Levels.Error, WebExp.StackTrace.ToString());
throw WebExp;
}
Любая помощь будет высоко ценится. Спасибо!