Guten Abend,
habe folgendes Problem, ich bin dabei ein Programm zu schreiben das automatisch mein Profil Bild bei SchuelerVz ändern soll. Für den Login habe ich einfach meine Daten in das Formular eingeben lassen, aber dies ist ja bei einem Upload nicht möglich, da Type=File. Also per VB Uploaden. Nur komme ich im Moment nicht weiter, habe schon Stundenlang das Internet abgesucht und niergends etwas passendes gefunden. Benutze Visual Basic 2005. Hier mein momentaner Code:
Dim HttpWebRequest As Net.HttpWebRequest = HttpWebRequest.Create( _
"http://www.schuelervz.net/Profile/EditImage")
Dim Boundary As String = "---------------------------" & _
DateTime.Now.Ticks.ToString
HttpWebRequest.Method = "POST"
HttpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1;" & _
"de; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2"
HttpWebRequest.Accept = _
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
HttpWebRequest.KeepAlive = "115"
HttpWebRequest.Referer = "http://www.schuelervz.net/Profile/EditImage"
HttpWebRequest.CookieContainer = New Net.CookieContainer()
HttpWebRequest.ContentType = "multipart/form-data; boundary=" & Boundary
'RequestStream Informationen
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=""image"";" & _
"filename=""20091218-215629-0123.jpg""" _
& Environment.NewLine & "Content-Type: image/jpeg" & _
Environment.NewLine & Environment.NewLine)
HttpWebRequest.ContentLength = BoundaryBytes.Length & InfoBytes.Length
Dim FileInfo As New IO.FileInfo("F:\Eigene Dateien\Eigene" & _
"Bilder\zak\20091218-215629-0123.jpg")
HttpWebRequest.ContentLength += FileInfo.Length
'RequestStream
Dim RequestStream As IO.Stream = HttpWebRequest.GetRequestStream
RequestStream.Write(BoundaryBytes, 0, BoundaryBytes.Length)
RequestStream.Write(InfoBytes, 0, InfoBytes.Length)
Dim FileStream As IO.FileStream = IO.File.Open("F:\Eigene" & _
"Dateien\Eigene Bilder\zak\20091218-215629-0123.jpg", _
IO.FileMode.Open)
Dim Buffer(1024) As Byte
Dim BytesRead As Integer
Do
BytesRead = FileStream.Read(Buffer, 0, Buffer.Length)
RequestStream.Write(Buffer, 0, BytesRead)
Loop Until BytesRead = 0
FileStream.Close()
RequestStream.Close()
'RequestStream Antwort
Dim HttpWebResponse As Net.HttpWebResponse = HttpWebRequest.GetResponse
MsgBox(HttpWebResponse) Fehler kommt ganz am Ende bei RequestStream.Close() und heißt WebException wurde nicht behandelt. Die Anfrage wurde abgebrochen: Die Anfrage wurde abgebrochen..
Was bedeutet das????
Hier noch der Log von httpHeader in Firefox bei einem Upload.
http://www.schuelervz.net/Profile/EditImage
POST /Profile/EditImage HTTP/1.1
Host: www.schuelervz.net
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.2) _
Gecko/20100316 Firefox/3.6.2
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: 115
Connection: keep-alive
Referer: http://www.schuelervz.net/Profile/EditImage
Cookie: _
s_pers=%20s_vsn_studivzschueler_1%3D3045353355938%7C1584887276654%3B%20s_nr%3_
D1269438750576-Repeat%7C1272030750576%3B; POPUPCHECK=1269460352077; _
PHPSESSID=6e029d70ffa69128bfb5d852608b535a71b909fc; Pm=Profile.EditImage_455; _
s_sess=%20s_cc%3Dtrue%3B%20s_sq%3Dstudivzschueler%253D%252526pid%25253DPvz_Pr_
ofile_EditImage%252526pidt%25253D1%252526oid%25253DFoto%25252520hochladen%252_
526oidt%25253D3%252526ot%25253DSUBMIT%3B; seq=14; _
SessionStorage=%7B%22TabGuid%22%3A%7B%22guid%22%3A1269438554556%7D%2C%22Sessi_
onActivity%22%3A%7B%22time%22%3A1269438554632%7D%2C%22ChatVisibility%22%3A%7B_
%22visible%22%3Afalse%2C%22opened%22%3Afalse%7D%2C%22LoginState%22%3A%7B%22lo_
ginState%22%3A%22on%22%7D%7D
Content-Type: multipart/form-data; _
boundary=---------------------------3035221901842
Content-Length: 232882
-----------------------------3035221901842
Content-Disposition: form-data; name="MAX_FILE_SIZE"
4300000
-----------------------------3035221901842
Content-Disposition: form-data; name="image"; filename="17-01-08_0853.jpg"
Content-Type: image/jpeg |