468,738 Members | 1,712 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,738 developers. It's quick & easy.

HttpWebRequest TimeOut On an Https channel while posting data

Hello,

When I'm uploading an file to a JRun WebServer (third party) with a Windows
Forms application, l always get an TimeOut while uploading, all other request
who doesn't request an post are going ok? Why? I've tried almost everything.
I also tried the KB888528 solution but this also doesn't work.

What can the KB887563 do for me?

Machine( tried on Windows 2003 Server & WinXp)
Microsoft .NET Framework 1.1 SP1

I'll hope somebody could help me because this is very frustrating.

Thanx in advance.

Greetz,

Joey Chömpff
My Code:

private void Initialize()
{
// Create a new request to the mentioned URL.
_request = (HttpWebRequest) WebRequest.Create(_url);

_request.Headers.Set("Pragma", "no-cache");
_request.UserAgent = "Sample";
_request.Timeout = 30000;
_request.Method = "GET";
_request.ContentType="text/xml";
_request.AllowAutoRedirect = true;
_request.KeepAlive = false;
_request.CookieContainer = _cookieJar;
_request.Credentials = CredentialCache.DefaultCredentials;
ServicePointManager.CertificatePolicy = new EBatchSecurityPolicy();

if (UseProxy)
{
_proxy = (WebProxy) _request.Proxy;
_proxy.Credentials = new NetworkCredential(_proxyUserName, _proxyPassword);
_request.Proxy=_proxy;
}
}

private void AddPostData()
{
string boundary = "---------------------------" +
DateTime.Now.Ticks.ToString("x");
_request.ContentType = "multipart/form-data; boundary=" + boundary;
_request.Method = "POST";

// Build up the post message header
StringBuilder sb = new StringBuilder();
sb.Append("--");
sb.Append(boundary);
sb.Append("\r\n");
sb.Append("Content-Disposition: form-data; name=\"");
sb.Append("file");
sb.Append("\"; filename=\"");
sb.Append(_fileNameToPost);
sb.Append("\"");
sb.Append("\r\n");
sb.Append("Content-Type: application/octet-stream");
sb.Append("\r\n");
sb.Append("\r\n");

string postHeader = sb.ToString();
byte[] postHeaderBytes = Encoding.Default.GetBytes(postHeader);

// Build the trailing boundary string as a byte array
// ensuring the boundary appears on a line by itself
byte[] boundaryBytes =
Encoding.Default.GetBytes(string.Format("\r\n--{0}--\r\n",boundary));

using(MemoryStream stream = new MemoryStream())
{
// Write out our post header
stream.Write(postHeaderBytes, 0, postHeaderBytes.Length);

// Write out the file contents
byte[] buffer = new Byte[checked((uint) Math.Min(4096, (int)
_dataToPost.Length))];
int bytesRead = 0;
int totalBytesRead = 0;
while ( (bytesRead = _dataToPost.Read(buffer, 0, buffer.Length)) != 0 )
{
stream.Write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
}

// Write out the trailing boundary
stream.Write(boundaryBytes, 0, boundaryBytes.Length);

long length = postHeaderBytes.Length + totalBytesRead +
boundaryBytes.Length;
_request.ContentLength = length;

using(Stream requestStream = _request.GetRequestStream())
{
stream.WriteTo(requestStream);
requestStream.Close();
}

stream.Close();
}
}

public ResponseBase GetResponse(Type responseType)
{
if (_dataToPost != null && _dataToPost.Length > 0)
AddPostData();
// Read the response
using(HttpWebResponse webResponse = (HttpWebResponse)_request.GetResponse())
{
ResponseBase response = null;
using (StreamReader sr = new
StreamReader(webResponse.GetResponseStream(), System.Text.UTF8Encoding.UTF8))
{
string responseString = sr.ReadToEnd();

using(StringReader stringReader = new StringReader(responseString))
{
response = (ResponseBase) Serializer.Read(responseType, stringReader);
stringReader.Close();
}
sr.Close();
}

webResponse.Close();
return response;
}
}

My Exception:

Message: The operation has timed-out. StackTrace: at
System.Net.HttpWebRequest.GetResponse()
at ECH.EBatch.Common.Communication.EBatchCommunicator .GetResponse(Type
responseType)
at ECH.EBatch.Common.EBatchManager.GetResponse(EBatch Service service,
String url, Type responseType, Stream dataToPost, String fileName)
at ECH.EBatch.Common.EBatchManager.UploadFile(String fileName,
EBatchService ebatchService)
at
ECH.EBatch.TestApplication.EBatchManagerTest.Uploa dOldFiles(EBatchService
service)
at ECH.EBatch.TestApplication.frmMain.btnUpload_Click (Object sender,
EventArgs e)
Nov 17 '05 #1
1 2732
I've seen that I didn't use the same encoding everywhere, but this wasnt the
solution.

I've tried to search my own post and then I saw an post from "Haacked" he
noticed something about "the Expect-100 problem". He had an url to his
WebLog who gave me a solotion of my problem
(http://haacked.com/archive/2004/05/15/449.aspx).

Thanx.

"Joey Chömpff" wrote:
Hello,

When I'm uploading an file to a JRun WebServer (third party) with a Windows
Forms application, l always get an TimeOut while uploading, all other request
who doesn't request an post are going ok? Why? I've tried almost everything.
I also tried the KB888528 solution but this also doesn't work.

What can the KB887563 do for me?

Machine( tried on Windows 2003 Server & WinXp)
Microsoft .NET Framework 1.1 SP1

I'll hope somebody could help me because this is very frustrating.

Thanx in advance.

Greetz,

Joey Chömpff
My Code:

private void Initialize()
{
// Create a new request to the mentioned URL.
_request = (HttpWebRequest) WebRequest.Create(_url);

_request.Headers.Set("Pragma", "no-cache");
_request.UserAgent = "Sample";
_request.Timeout = 30000;
_request.Method = "GET";
_request.ContentType="text/xml";
_request.AllowAutoRedirect = true;
_request.KeepAlive = false;
_request.CookieContainer = _cookieJar;
_request.Credentials = CredentialCache.DefaultCredentials;
ServicePointManager.CertificatePolicy = new EBatchSecurityPolicy();

if (UseProxy)
{
_proxy = (WebProxy) _request.Proxy;
_proxy.Credentials = new NetworkCredential(_proxyUserName, _proxyPassword);
_request.Proxy=_proxy;
}
}

private void AddPostData()
{
string boundary = "---------------------------" +
DateTime.Now.Ticks.ToString("x");
_request.ContentType = "multipart/form-data; boundary=" + boundary;
_request.Method = "POST";

// Build up the post message header
StringBuilder sb = new StringBuilder();
sb.Append("--");
sb.Append(boundary);
sb.Append("\r\n");
sb.Append("Content-Disposition: form-data; name=\"");
sb.Append("file");
sb.Append("\"; filename=\"");
sb.Append(_fileNameToPost);
sb.Append("\"");
sb.Append("\r\n");
sb.Append("Content-Type: application/octet-stream");
sb.Append("\r\n");
sb.Append("\r\n");

string postHeader = sb.ToString();
byte[] postHeaderBytes = Encoding.Default.GetBytes(postHeader);

// Build the trailing boundary string as a byte array
// ensuring the boundary appears on a line by itself
byte[] boundaryBytes =
Encoding.Default.GetBytes(string.Format("\r\n--{0}--\r\n",boundary));

using(MemoryStream stream = new MemoryStream())
{
// Write out our post header
stream.Write(postHeaderBytes, 0, postHeaderBytes.Length);

// Write out the file contents
byte[] buffer = new Byte[checked((uint) Math.Min(4096, (int)
_dataToPost.Length))];
int bytesRead = 0;
int totalBytesRead = 0;
while ( (bytesRead = _dataToPost.Read(buffer, 0, buffer.Length)) != 0 )
{
stream.Write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
}

// Write out the trailing boundary
stream.Write(boundaryBytes, 0, boundaryBytes.Length);

long length = postHeaderBytes.Length + totalBytesRead +
boundaryBytes.Length;
_request.ContentLength = length;

using(Stream requestStream = _request.GetRequestStream())
{
stream.WriteTo(requestStream);
requestStream.Close();
}

stream.Close();
}
}

public ResponseBase GetResponse(Type responseType)
{
if (_dataToPost != null && _dataToPost.Length > 0)
AddPostData();
// Read the response
using(HttpWebResponse webResponse = (HttpWebResponse)_request.GetResponse())
{
ResponseBase response = null;
using (StreamReader sr = new
StreamReader(webResponse.GetResponseStream(), System.Text.UTF8Encoding.UTF8))
{
string responseString = sr.ReadToEnd();

using(StringReader stringReader = new StringReader(responseString))
{
response = (ResponseBase) Serializer.Read(responseType, stringReader);
stringReader.Close();
}
sr.Close();
}

webResponse.Close();
return response;
}
}

My Exception:

Message: The operation has timed-out. StackTrace: at
System.Net.HttpWebRequest.GetResponse()
at ECH.EBatch.Common.Communication.EBatchCommunicator .GetResponse(Type
responseType)
at ECH.EBatch.Common.EBatchManager.GetResponse(EBatch Service service,
String url, Type responseType, Stream dataToPost, String fileName)
at ECH.EBatch.Common.EBatchManager.UploadFile(String fileName,
EBatchService ebatchService)
at
ECH.EBatch.TestApplication.EBatchManagerTest.Uploa dOldFiles(EBatchService
service)
at ECH.EBatch.TestApplication.frmMain.btnUpload_Click (Object sender,
EventArgs e)

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Gregory A Greenman | last post: by
9 posts views Thread by Mike Cronin via DotNetMonster.com | last post: by
9 posts views Thread by Michael Evanchik | last post: by
8 posts views Thread by Soeren S. Joergensen | last post: by
9 posts views Thread by Matt Sollars | last post: by
1 post views Thread by Kevin Landymore | last post: by
reply views Thread by zhoujie | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.