Hallo Leute, ich habe vor eine Datei per httprequest auf einen Webspace zu schicken. Leider funzt das irgendwie nicht - er läd manchmal einfach nur eine Leere Datei hoch.
Unter anderem gibt er mir als Response auch nur den Quelltext aus, nicht aber den download link, danke für die Hilfe!
Unter anderem gibt er mir als Response auch nur den Quelltext aus, nicht aber den download link, danke für die Hilfe!
Code:
'File einlesen Dim location As String = "C:\Dokumente und Einstellungen\xxx\Desktop\testing\bla.txt" Dim b = txt_ReadAll(location) Dim Endung As String = fRight(location, (location).Length - InStrRev(location, ".") - 1) Dim boundary As String = CreateBoundary() Dim req As Net.HttpWebRequest = Net.HttpWebRequest.Create("http://www.xxx/exec/xupload.php") req.Credentials = System.Net.CredentialCache.DefaultCredentials req.Method = "POST" req.UserAgent = "spiTe-checKer/1.10 (Windows 7; U; de)" 'req.Headers.Add(HttpRequestHeader.Host, req.Accept = "Accept: application/xhtml+voice+xml;version=1.2, application/x-xhtml+voice+xml;version=1.2, text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1" req.Headers.Add(Net.HttpRequestHeader.AcceptLanguage, "de-DE,de;q=0.9,en;q=0.8") req.Headers.Add(Net.HttpRequestHeader.AcceptCharset, "iso-8859-1, utf-8, utf-16, *;q=0.1") req.Headers.Add(Net.HttpRequestHeader.AcceptEncoding, "deflate, gzip, x-gzip, identity, *;q=0") req.Referer = "xxx" req.KeepAlive = True req.Connection = "TE" req.Headers.Add(Net.HttpRequestHeader.Te, "deflate, gzip, chunked, identity, trailers") req.ContentLength = (b).Length + 449 'bist das File req.ContentType = "Content-Type: multipart/form-data; boundary=" & boundary req.ServicePoint.Expect100Continue = False Dim boundarybytes() As Byte = System.Text.Encoding.ASCII.GetBytes("--" & boundary & Environment.NewLine) Dim postData As New StringBuilder postData.AppendLine("Content-Type: multipart/form-data; boundary=" & boundary) postData.AppendLine("") postData.AppendLine("--" & boundary) postData.AppendLine("Content-Disposition: form-data; name=""F1""; filename=""bla.txt""") postData.AppendLine("Content-Type: " & MIMEFileType(Endung)) postData.AppendLine("") postData.AppendLine(b) postData.AppendLine("--" & boundary) postData.AppendLine("Content-Disposition: form-data; name=""MAX_FILE_SIZE""") postData.AppendLine("") postData.AppendLine("5000000") postData.AppendLine("--" & boundary) postData.AppendLine("Content-Disposition: form-data; name=""passwort""") postData.AppendLine("") postData.AppendLine("testing") postData.AppendLine("--" & boundary) postData.AppendLine("Content-Disposition: form-data; name=""tn_size""") postData.Append("--" & boundary & "--") Dim infobytes As Byte() = Encoding.ASCII.GetBytes(postData.ToString) req.ContentLength = boundarybytes.Length + infobytes.Length Dim fileinfo As New IO.FileInfo(location) req.ContentLength += fileinfo.Length Dim reqstream As IO.Stream = req.GetRequestStream 'Request ausgeben lassen zur Kontrolle' MsgBox(req.Headers.ToString) reqstream.Write(boundarybytes, 0, boundarybytes.Length) reqstream.Write(infobytes, 0, infobytes.Length) Dim FileStream As IO.FileStream = IO.File.Open(location, _ IO.FileMode.Open) Dim buffer(1023) As Byte Dim bytesRead As Integer Do bytesRead = FileStream.Read(buffer, 0, buffer.Length) reqstream.Write(buffer, 0, bytesRead) Loop Until bytesRead = 0 FileStream.Close() reqstream.Close() Dim resp As Net.HttpWebResponse = req.GetResponse Dim reader As IO.StreamReader = New IO.StreamReader( _ resp.GetResponseStream()) Dim responseFromServer As String = reader.ReadToEnd() 'Kontroll MSG-Box' Debug.WriteLine(responseFromServer) 'Zur Kontrolle noch einmal in eine txt Datei' 'Dim oSW As New IO.StreamWriter(location) 'oSW.Write(responseFromServer) 'oSW.Close() reader.Close() resp.Close()