Upload über PHP-Skript

Afritus

Mitglied
Hi,

ich will nun ein Bild oder eine Textdatei über ein PHP-Skript, das ich mir geschrieben hab, auf einen Server laden.
PHP-Skript: http://umbdata.esport-masters.com
Es ist so aufgebaut:
Man sucht sich eine Datei aus, gibt dann bei Passwort das Upload-Passwort ein und bei Ordner den jeweiligen Unterordner.
Das PHP-Skript funktioniert auch, wenn ich es selber bediene.

Nun will ich aber via HttpWebRequest von meinem VB-Programm aus eine Datei hochladen. Deshalb habe ich den Netzwerkverkehr, der bei diesem Skript entsteht, mal mitgeloggt:

Code:
http://umbdata.esport-masters.com/

POST / HTTP/1.1
Host: umbdata.esport-masters.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://umbdata.esport-masters.com/
Content-Type: multipart/form-data; boundary=---------------------------265001916915724
Content-Length: 2665
-----------------------------265001916915724
Content-Disposition: form-data; name="datei"; filename="mitschnitt.txt"
Content-Type: text/plain

http://umbdata.esport-masters.com/

GET / HTTP/1.1
Host: umbdata.esport-masters.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

HTTP/1.x 200 OK
Date: Sun, 07 Feb 2010 12:28:19 GMT
Server: Apache/2.2.14 (EL)
X-Powered-By: PHP/5.2.11
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=ISO-8859-1
----------------------------------------------------------
http://umbdata.esport-masters.com/favicon.ico

GET /favicon.ico HTTP/1.1
Host: umbdata.esport-masters.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

HTTP/1.x 404 Not Found
Date: Sun, 07 Feb 2010 12:28:22 GMT
Server: Apache/2.2.14 (EL)
Content-Length: 297
Connection: close
Content-Type: text/html; charset=iso-8859-1
----------------------------------------------------------
http://umbdata.esport-masters.com/

POST / HTTP/1.1
Host: umbdata.esport-masters.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://umbdata.esport-masters.com/

HTTP/1.x 200 OK
Date: Sun, 07 Feb 2010 12:28:46 GMT
Server: Apache/2.2.14 (EL)
X-Powered-By: PHP/5.2.11
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=ISO-8859-1
----------------------------------------------------------

-----------------------------265001916915724
Content-Disposition: form-data; name="passwort"

EsportMastersUmbrella2010-02
-----------------------------265001916915724
Content-Disposition: form-data; name="ordner"

100
-----------------------------265001916915724
Content-Disposition: form-data; name="submit"

Daten absenden
-----------------------------265001916915724--

HTTP/1.x 200 OK
Date: Sun, 07 Feb 2010 17:34:21 GMT
Server: Apache/2.2.14 (EL)
X-Powered-By: PHP/5.2.11
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=ISO-8859-1
----------------------------------------------------------

Bisher habe ich diesen VB-Code:

Code:
Dim boundary As String = "---------------------------" & DateTime.Now.Ticks.ToString

        Dim req As HttpWebRequest = HttpWebRequest.Create("http://umbdata.esport-masters.com/")
        req.Credentials = System.Net.CredentialCache.DefaultCredentials
        req.ServicePoint.Expect100Continue = False
        req.Method = "POST"
        req.KeepAlive = True
        req.ContentType = "multipart/form-data; boundary=" & boundary
        req.Referer = "http://umbdata.esport-masters.com/"
        req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7"
        req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"

        Dim boundarybytes() As Byte = System.Text.Encoding.ASCII.GetBytes(("--" + boundary & Environment.NewLine))
        Dim infobytes() As Byte = System.Text.Encoding.ASCII.GetBytes("Content-Disposition: form-data; ""name=""datei""; ""filename=""mitschnitt.txt""; ""name=""passwort""; ""passwort=""EsportMastersUmbrella2010-02""; ""name=""ordner""; ""tmp_name=""100""" & Environment.NewLine & "Content-Type: text/plain" & Environment.NewLine & Environment.NewLine)

        req.ContentLength = boundarybytes.Length + infobytes.Length

        Dim fileinfo As New FileInfo(My.Computer.FileSystem.SpecialDirectories.Desktop & "/mitschnitt.txt")
        req.ContentLength += fileinfo.Length

        Dim reqstream As Stream = req.GetRequestStream

        'schreiben
        reqstream.Write(boundarybytes, 0, boundarybytes.Length)
        reqstream.Write(infobytes, 0, infobytes.Length)


        Dim FileStream As FileStream = File.Open(My.Computer.FileSystem.SpecialDirectories.Desktop & "/mitschnitt.txt", FileMode.Open)

        Dim buffer(1024) 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 HttpWebResponse = req.GetResponse

Jedoch funktioniert es leider nicht, es wird keine Datei hochgeladen. Was habe ich falsch gemacht?

MfG
Markus

## EDIT ##

Unter Umständen könnte man es ja auch so irgendwie machen:

Code:
WebBrowser1.Document.GetElementById("passwort").InnerText = "EsportMastersUmbrella2010-02"
        WebBrowser1.Document.GetElementById("ordner").InnerText = "100"
        WebBrowser1.Document.GetElementById("submit").InvokeMember("click")

Nur ich weiß nicht, wie ich da die Datei aussuchen kann.

MfG
 
Zurück