Hallo, ich versuche gerade einen Pictureupload zu bewerkstelligen. Dieses Codebeispiel habe ich im Netz gefunden und mittels live http headers habe ich versucht das Konstrukt nachzubauen.. Ohne erfolg.
Könnt ihr mir helfen?
Live HTTP Headers:
Was mach ich falsch?
Könnt ihr mir helfen?
VB.NET-Quellcode
- Imports System.IO
- Imports System.Net
- Imports System.Text
- Public Class Form1
- Structure UploadData
- Dim Fieldname As String
- Dim Filename As String
- Dim Content As Byte()
- Public Sub New(ByVal fieldname As String, ByVal filename As String, ByVal content As Byte())
- Me.Fieldname = fieldname
- Me.Filename = filename
- Me.Content = content
- End Sub
- End Structure
- Public Function GetContentType(ByVal path As String) As String
- Select Case New FileInfo(Path).Extension.ToLower()
- Case ".bmp"
- Return "image/bmp"
- Case ".gif"
- Return "image/gif"
- Case ".jpe", ".jpeg", ".jpg"
- Return "image/jpeg"
- Case ".png"
- Return "image/png"
- Case ".svg"
- Return "image/svg+xml"
- Case ".tif", ".tiff"
- Return "image/tiff"
- Case Else
- Return "application/octet-stream"
- End Select
- End Function
- Public Function GetUploadResponse(ByVal url As String, ByVal upload As UploadData) As String
- Dim boundary As String = Guid.NewGuid().ToString().Replace("-", "")
- Dim request As HttpWebRequest = CType(HttpWebRequest.Create(url), HttpWebRequest)
- request.Method = "POST"
- request.ContentType = "multipart/form-data; boundary=" & boundary
- request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0"
- Dim PostData As New MemoryStream
- With New StreamWriter(PostData)
- .Write("Host: www.directupload.net")
- .Write("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
- .Write("Accept-Language: de,en-US;q=0.7,en;q=0.3")
- .Write("Accept-Encoding: gzip, deflate")
- .Write("Referer: http://www.directupload.net/")
- .Write("Connection: keep-alive")
- .Write("Upgrade-Insecure-Requests: 1")
- .Write(("--" & boundary) & vbNewLine)
- .Write("Content-Disposition: form-data; name=""{0}""; filename=""{1}""{2}", upload.Fieldname, upload.Filename, vbNewLine)
- .Write(("Content-Type: " & GetContentType(upload.Filename) & vbNewLine) & vbNewLine)
- .Flush()
- .Write(vbNewLine)
- .Write("--{0}--{1}", boundary, vbNewLine)
- PostData.Write(upload.Content, 0, upload.Content.Length)
- .Flush()
- End With
- request.ContentLength = PostData.Length
- Using s As Stream = request.GetRequestStream()
- PostData.WriteTo(s)
- End Using
- PostData.Close()
- Return New StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd()
- End Function
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim upload As New UploadData("files[]", "C:\Users\Daniel\Desktop\17952987_1337511523003217_4207780162341162631_n.jpg", File.ReadAllBytes("C:\Users\Daniel\Desktop\17952987_1337511523003217_4207780162341162631_n.jpg"))
- Dim html As String = GetUploadResponse("http://www.directupload.net/index.php?mode=upload", upload)
- TextBox1.Text = html
- End Sub
- End Class
Live HTTP Headers:
http://www.directupload.net/index.php?mode=upload
POST /index.php?mode=upload HTTP/1.1
Host: directupload.net
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: directupload.net/
Cookie: *************************************************
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Content-Type: multipart/form-data; boundary=---------------------------176211200817433
Content-Length: 23452
-----------------------------176211200817433
Content-Disposition: form-data; name="bilddatei"; filename="17992342_1289222974532628_7319340441188498046_n.jpg"
Content-Type: image/jpeg
ÿØÿà
HTTP/1.1 200 OK
Date: Sun, 23 Apr 2017 18:39:47 GMT
Server: Apache/2.2.16 (Debian)
X-Powered-By: PHP/5.3.3-7+squeeze14
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
Was mach ich falsch?
Liebe Grüße,
C.O.D.E
Testautomatisierung (TA):
C.O.D.E
Testautomatisierung (TA):
5%
Du findest meinen Beitrag Hilfreich? Dann drück auf Hilfreich!
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „pc-werkstatt“ ()