Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / June 2005

Tip: Looking for answers? Try searching our database.

HttpWebRequest TimeOut On an Https channel while posting data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joey Chömpff - 28 Jun 2005 11:45 GMT
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(EBatchService service,
String url, Type responseType, Stream dataToPost, String fileName)
  at ECH.EBatch.Common.EBatchManager.UploadFile(String fileName,
EBatchService ebatchService)
  at
ECH.EBatch.TestApplication.EBatchManagerTest.UploadOldFiles(EBatchService
service)
  at ECH.EBatch.TestApplication.frmMain.btnUpload_Click(Object sender,
EventArgs e)
Joey Chömpff - 28 Jun 2005 13:07 GMT
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.

> Hello,
>
[quoted text clipped - 146 lines]
>    at ECH.EBatch.TestApplication.frmMain.btnUpload_Click(Object sender,
> EventArgs e)

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.