Search code examples
vb.nethttpwebrequesthttpwebresponse

vb.net webclient class throw an out of memory exception


I use VB.Net with VisualStudio 2015 and .net 4.5.2.

I use the System.Net.WebClient class to UPLOAD ASYNC FILES into a webserver with the methode UploadFileAsync(address as URI, fileName as string) but a System.OutOfMemoryException accured when the fileSize is too large...

Any idea?

Thank you!


Solution

  • Resolved.

    There was an error here :

    postStreamHeaders = boundary & vbCrLf & "Content-Disposition: form-data; name=""var1""" & vbCrLf & vbCrLf & "val1" & vbCrLf
    postStreamHeaders = boundary & vbCrLf & "Content-Disposition: form-data; name=""var2""" & vbCrLf & vbCrLf & "val2" & vbCrLf
    postStreamFooters = boundary & "--"
    

    The good syntax is :

    postStreamHeaders = "--" & boundary & vbCrLf & "Content-Disposition: form-data; name=""var1""" & vbCrLf & vbCrLf & "val1" & vbCrLf
    postStreamHeaders &= "--" & boundary & vbCrLf & "Content-Disposition: form-data; name=""var2""" & vbCrLf & vbCrLf & "val2" & vbCrLf
    postStreamFooters = "--" & boundary & "--" & vbCrLf
    

    Hope this may help someone else ...