jeg lavede engang det her eksempel paa en 2 fils upload:
Imports System
Imports System.IO
Imports System.Net
Public Class FileUpload
Private Const BOUNDARY As String = "ArneArne"
Public Shared Sub Main(ByVal args As String())
upload("
http://localhost/upload2.php", "C:\size.exe")
upload("
http://localhost/upload2.php", "C:\big.exe")
End Sub
Public Shared Sub upload(ByVal url As String, ByVal binfile As String)
Dim req As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
req.Method = "POST"
req.ContentType = "multipart/form-data, boundary=" + BOUNDARY
Dim post As StreamWriter = New StreamWriter (req.GetRequestStream)
post.WriteLine("--" + BOUNDARY)
post.WriteLine("Content-disposition: attachment; name=""filename[1]""; filename=""" + binfile + """")
post.WriteLine("Content-type: application/octet-stream")
post.WriteLine("Content-Transfer-Encoding: binary")
post.WriteLine("")
post.Flush
Dim binf As Stream = New FileStream (binfile, FileMode.Open)
Dim c As Integer
While (c = binf.ReadByte) >= 0
post.BaseStream.WriteByte(CType(c, Byte))
End While
binf.Close
post.BaseStream.Flush
post.Close
Dim resp As HttpWebResponse = CType(req.GetResponse, HttpWebResponse)
Console.WriteLine(resp.StatusCode)
resp.Close
End Sub
End Class