Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

HTTPWebResponse Error: Unable to read data from the transport connection

Posted on 2009-05-19
2
Medium Priority
?
2,887 Views
Last Modified: 2013-12-17
I have some code for uploading a file to a HTTPS server.  The code works great for files up to about 150 MB (not sure of the exact cutoff).   But when the files get bigger than that, then I get the following exception:

    "Unable to write data to the transport connection:  An existing connection was forcibly
    closed by the remote host"

    The BaseException is:  "Unable to read data from the transport connection"


Other users (outside our network) can already successfully upload files up to almost 1 GB with no problems...  it just my code that's not working...

I've searched the internet for hours and haven't found the answer.  Please help. Thanks!

VBRocks

'This the core code from a dll class that works with a windows form.
 
        'Get the length of the selected file
        Dim fi As IO.FileInfo = My.Computer.FileSystem.GetFileInfo(filePath)
        Dim fileLength As Long = fi.Length
 
        'Create the request
        Dim request As HttpWebRequest = _
            DirectCast(HttpWebRequest.Create(address), HttpWebRequest)
 
        'Configure request
        request.Credentials = New System.Net.NetworkCredential("UserName", "Password")
 
        request.Method = WebRequestMethods.Http.Put
        request.KeepAlive = True
        request.Timeout = -1
        request.ContentLength = fileLength.ToString()
 
         'This is required for our WebDav server 
         request.SendChunked = True
         request.Headers.Add("Translate: f")
         request.AllowWriteStreamBuffering = True
 
         Dim s As IO.Stream = request.GetRequestStream()
 
        Dim fs As New IO.FileStream(filePath, IO.FileMode.Open, IO.FileAccess.Read)
        Dim byteTransferRate As Integer = 1024     
        Dim bytes(byteTransferRate - 1) As Byte        
        Dim bytesRead As Integer = 0
        Dim totalBytesRead As Long = 0
 
        Do
            bytesRead = fs.Read(bytes, 0, bytes.Length)
 
            If bytesRead > 0 Then
 
                totalBytesRead += bytesRead
 
                'Write to stream
                s.Write(bytes, 0, bytesRead)
 
            End If
 
        Loop While bytesRead > 0
 
        s.Close()
        s.Dispose()
        s = Nothing
 
        fs.Close()
        fs.Dispose()
        fs = Nothing
 
 
         'It basically hangs here for over 10 minutes and then produces the error.
         Dim response As HttpWebResponse = DirectCast(request.GetResponse(), _
             HttpWebResponse)

Open in new window

0
Comment
Question by:VBRocks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 27

Author Comment

by:VBRocks
ID: 24426880
Oops... The base exception is:

    "An existing connection was forcibly closed by the remote host"

0
 
LVL 27

Accepted Solution

by:
VBRocks earned 0 total points
ID: 24503697
Alas...  I found the answer.  I thought it was hopeless, and had to be abandoned.  But it was not hopeless.  I was able to use the following article to make it work:

     http://support.microsoft.com/kb/908573

If you're having the same or similar problem, find out exactly what type of authentication your server is requiring (ie.:  Basic, Digest, Kerberos, Negotiate, NTLM), and then be patient and work through this Miscroft Support page.  It will help you solve your problem, and you will still be able to use the HttpWebRequest class.

0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question