[Mono-bugs] [Bug 603794] HttpWebRequest ReadWriteTimeout ignored
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Mon Jul 19 02:55:24 EDT 2010
http://bugzilla.novell.com/show_bug.cgi?id=603794
http://bugzilla.novell.com/show_bug.cgi?id=603794#c2
--- Comment #2 from Fabio Colledani <fcolle at tiscalinet.it> 2010-07-19 06:55:22 UTC ---
(In reply to comment #1)
> We need a small test case for this. I'm sure that whatever test I come up with
> based on your description is going to be different from yours.
Just OPEN the source file! The timeout is just saved in the class but NEVER
used!
Anyways, you can use the following method to upload data to a web server (you
have to setup the server too). During the upload phase, disconnect the network
wires. You will see that the timeout never expires.
[CODE]
public static bool updateCgi(byte[] updatePackageFile,string ipaddress,int
port , string uri, string password, int requestTimeout, int readWriteTimeout,
out string responseStr)
{
ILog logger = LogManager.GetLogger(typeof(CgiAdapter));
try
{
SetAllowUnsafeHeaderParsing20();
string boundary = "SOLBoundary--";
byte[] boudaryBytes = Encoding.ASCII.GetBytes("\r\n--" +
boundary + "\r\n");
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create("http://"+ipaddress+":"+port.ToString()+"/"+uri);
req.KeepAlive = true;
req.ProtocolVersion = HttpVersion.Version11;
req.Method = "POST";
req.ContentType = "multipart/form-data; boundary=" + boundary;
//Setting up the cookies if needed
req.CookieContainer = new CookieContainer(2);
Cookie authCookie = new Cookie("lpassword", "mypassword",
"/cgi-bin/", ipaddress);
Cookie langCookie = new Cookie("language", "English",
"/cgi-bin/", ipaddress);
req.CookieContainer.Add(authCookie);
req.CookieContainer.Add(langCookie);
req.Timeout = requestTimeout * 1000;
req.ReadWriteTimeout = readWriteTimeout * 1000;
//Template per il descrittore del contenitore per i valori dei
parametri (input del form)
string formatDataTemplate = "\r\n--" + boundary +
"\r\nContent-Disposition: form-data; name=\"{0}\";\r\n\r\n{1}";
//Template per i file
string fileFormatDataTemplate = "\r\n--" + boundary +
"\r\nContent-Disposition: form-data; name=\"{0}\";filename=\"{1}\"\r\n";
MemoryStream ms = new MemoryStream();
//prima parte: xmlout=true
string xmlOutItem = string.Format(formatDataTemplate, "xmlout",
"true");
byte[] xmlOutBytes = Encoding.UTF8.GetBytes(xmlOutItem);
ms.Write(xmlOutBytes, 0, xmlOutBytes.Length);
//application/x-compressed
string fileHeader = string.Format(fileFormatDataTemplate,
"tarfile", "update.tgz");
fileHeader += "Content-Type: application/x-compressed\r\n\r\n";
byte[] fileHeaderBytes = Encoding.UTF8.GetBytes(fileHeader);
ms.Write(fileHeaderBytes, 0, fileHeaderBytes.Length);
ms.Write(updatePackageFile, 0, updatePackageFile.Length);
//chiudo con l'ultimo bondary + due trattini
ms.Write(boudaryBytes, 0, boudaryBytes.Length);
byte[] dashesBytes = Encoding.UTF8.GetBytes("--");
ms.Write(dashesBytes, 0, dashesBytes.Length);
ms.Position = 0;
//Invio di tutto il buffer con la chiamata POST
byte[] postBuffer = new byte[ms.Length];
ms.Read(postBuffer, 0, postBuffer.Length);
ms.Close();
req.ContentLength = postBuffer.Length;
string postReqStr = Encoding.ASCII.GetString(postBuffer);
Stream requestStream = req.GetRequestStream();
requestStream.Write(postBuffer, 0, postBuffer.Length);
requestStream.Close();
if (logger.IsDebugEnabled)
logger.Debug("Sent " + postBuffer.Length + " bytes to " +
ipaddress);
//Ricezione della risposta
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
if (resp.StatusCode != HttpStatusCode.OK)
{
responseStr = "HTTP ERROR : [" + resp.StatusCode.ToString()
+ "]";
return false;
}
else
{
Stream responseStream = resp.GetResponseStream();
StreamReader respReader = new StreamReader(responseStream);
responseStr = respReader.ReadToEnd();
logger.Debug("HTTP Response: " + responseStr);
resp.Close();
req = null;
resp = null;
//throw new NotImplementedException();
return true;
}
}
catch (Exception excp)
{
logger.Error(excp.Message, excp);
responseStr = excp.Message;
return false;
}
}
[/CODE]
--
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list