upload file and send value

srdva59

Active member
Joined
Feb 21, 2009
Messages
28
Programming Experience
Beginner
hi,
i looking for a way to upload a image or file and a value too using the vb.net so
far i found this that can send the image i have tested and is fine :)
but i can´t understand how put a value to be returned by this:
$_POST["value"] i have other code that can send the value by post and works fine but
i need change this code to send post values too
any one can help me?
thanks a lot :)

Dim filepath As String = IO.Path.Combine(Application.StartupPath, "filename.ext")
Dim url As String = "http://www.FAKESITE.com/php/Upload/index.php"

Dim boundary As String = IO.Path.GetRandomFileName
Dim header As New System.Text.StringBuilder()
header.AppendLine("--" & boundary)
header.Append("Content-Disposition: form-data; name=""uploaded_file"";")
header.AppendFormat("filename=""{0}""", IO.Path.GetFileName(filepath))
header.AppendLine()
header.AppendLine("Content-Type: application/octet-stream")
header.AppendLine()

Dim headerbytes() As Byte = System.Text.Encoding.UTF8.GetBytes(header.ToString)
Dim endboundarybytes() As Byte = System.Text.Encoding.ASCII.GetBytes(vbNewLine & "--" & boundary & "--" & vbNewLine)

Dim req As Net.HttpWebRequest = Net.HttpWebRequest.Create(url)
req.ContentType = "multipart/form-data; boundary=" & boundary
req.ContentLength = headerbytes.Length + New IO.FileInfo(filepath).Length + endboundarybytes.Length
req.Method = "POST"

Dim s As IO.Stream = req.GetRequestStream
s.Write(headerbytes, 0, headerbytes.Length)
Dim filebytes() As Byte = My.Computer.FileSystem.ReadAllBytes(filepath)
s.Write(filebytes, 0, filebytes.Length)
s.Write(endboundarybytes, 0, endboundarybytes.Length)
s.Close()
 
Back
Top