Boundary-POST via Webrequest übergeben funktioniert nicht

  • VB.NET

Es gibt 5 Antworten in diesem Thema. Der letzte Beitrag () ist von mewcrazy.

    Boundary-POST via Webrequest übergeben funktioniert nicht

    Hallo,
    und zwar möchte ich gerne bei einer Seite ein Formular übertragen. Dieses Formular "arbeitet" nicht mit normalen POSTs, sondern mit den Boundarys. Nun habe ich also den Boundary-Content nachgestellt und via WebRequest abgeschickt. Allerdings akzeptiert die Seite anscheinend meinen POST nicht, da ich im Quelltext keine Bestätigung finden kann, die normalerweise fest auf der Seite ist bei einem erfolgreichen Eintrag.

    LiveHTTPHeader-Ausschnitt:
    Spoiler anzeigen

    XML-Quellcode

    1. http://www."google.de"/ui.php?ua=tvshow&do=add
    2. POST /ui.php?ua=tvshow&do=add HTTP/1.1
    3. Host: www."google.de"
    4. User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.8;MEGAUPLOAD 1.0
    5. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    6. Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
    7. Accept-Encoding: gzip,deflate
    8. Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    9. Keep-Alive: 115
    10. Connection: keep-alive
    11. Referer: http://www."google.de"/ui.php?ua=tvshow&do=add
    12. Cookie: lang=de; __utma=227930369.10588397.1284951760.1285532059.1285534788.21; __utmz=227930369.1285251781.4.2.utmcsr=xmarks.com|utmccn=(referral)|utmcmd=referral|utmcct=/topic/stream_seiten; lastview=189518; onlylanguage=de; PHPSESSID=72hdvld86ugv0c6ke173m7aut0; __utmc=227930369; __utmb=227930369.18.10.1285534788
    13. Content-Type: multipart/form-data; boundary=---------------------------130281863114589
    14. Content-Length: 4253
    15. -----------------------------130281863114589
    16. Content-Disposition: form-data; name="title"
    17. Alle Hassen Chris
    18. -----------------------------130281863114589
    19. Content-Disposition: form-data; name="season"
    20. 01
    21. -----------------------------130281863114589
    22. Content-Disposition: form-data; name="episode"
    23. 16
    24. -----------------------------130281863114589
    25. Content-Disposition: form-data; name="language"
    26. 2
    27. -----------------------------130281863114589
    28. Content-Disposition: form-data; name="hoster"
    29. 94
    30. -----------------------------130281863114589
    31. Content-Disposition: form-data; name="link"
    32. http://www.filestage.to/watch/08517ad3ecf5562dad2d29aa39e878b4/Alle.hassen.Chris.S01E16.Chris.hasst.die.Gicht_randomanon.avi
    33. -----------------------------130281863114589
    34. Content-Disposition: form-data; name="genre1"
    35. -----------------------------130281863114589
    36. Content-Disposition: form-data; name="genre2"
    37. -----------------------------130281863114589
    38. Content-Disposition: form-data; name="genre3"
    39. -----------------------------130281863114589
    40. Content-Disposition: form-data; name="genre4"
    41. -----------------------------130281863114589
    42. Content-Disposition: form-data; name="genre5"
    43. -----------------------------130281863114589
    44. Content-Disposition: form-data; name="thumbnail"
    45. upload
    46. -----------------------------130281863114589
    47. Content-Disposition: form-data; name="thumbnailfile"; filename=""
    48. Content-Type: application/octet-stream
    49. -----------------------------130281863114589
    50. Content-Disposition: form-data; name="thumbnaillink"
    51. -----------------------------130281863114589
    52. Content-Disposition: form-data; name="description"
    53. -----------------------------130281863114589
    54. Content-Disposition: form-data; name="duration"
    55. -----------------------------130281863114589
    56. Content-Disposition: form-data; name="fsk"
    57. -----------------------------130281863114589
    58. Content-Disposition: form-data; name="countryyear"
    59. -----------------------------130281863114589
    60. Content-Disposition: form-data; name="director"
    61. -----------------------------130281863114589
    62. Content-Disposition: form-data; name="actors"
    63. -----------------------------130281863114589
    64. Content-Disposition: form-data; name="detail[1]"
    65. -----------------------------130281863114589
    66. Content-Disposition: form-data; name="detailtext[1]"
    67. -----------------------------130281863114589
    68. Content-Disposition: form-data; name="detail[2]"
    69. -----------------------------130281863114589
    70. Content-Disposition: form-data; name="detailtext[2]"
    71. -----------------------------130281863114589
    72. Content-Disposition: form-data; name="detail[3]"
    73. -----------------------------130281863114589
    74. Content-Disposition: form-data; name="detailtext[3]"
    75. -----------------------------130281863114589
    76. Content-Disposition: form-data; name="detail[4]"
    77. -----------------------------130281863114589
    78. Content-Disposition: form-data; name="detailtext[4]"
    79. -----------------------------130281863114589
    80. Content-Disposition: form-data; name="detail[5]"
    81. -----------------------------130281863114589
    82. Content-Disposition: form-data; name="detailtext[5]"
    83. -----------------------------130281863114589
    84. Content-Disposition: form-data; name="detail[6]"
    85. -----------------------------130281863114589
    86. Content-Disposition: form-data; name="detailtext[6]"
    87. -----------------------------130281863114589
    88. Content-Disposition: form-data; name="detail[7]"
    89. -----------------------------130281863114589
    90. Content-Disposition: form-data; name="detailtext[7]"
    91. -----------------------------130281863114589
    92. Content-Disposition: form-data; name="detail[8]"
    93. -----------------------------130281863114589
    94. Content-Disposition: form-data; name="detailtext[8]"
    95. -----------------------------130281863114589
    96. Content-Disposition: form-data; name="detail[9]"
    97. -----------------------------130281863114589
    98. Content-Disposition: form-data; name="detailtext[9]"
    99. -----------------------------130281863114589
    100. Content-Disposition: form-data; name="adtext"
    101. -----------------------------130281863114589
    102. Content-Disposition: form-data; name="adlink"
    103. -----------------------------130281863114589--
    104. HTTP/1.1 200 OK
    105. Server: nginx/0.6.32
    106. Date: Sun, 26 Sep 2010 21:41:09 GMT
    107. Content-Type: text/html
    108. Transfer-Encoding: chunked
    109. Connection: keep-alive
    110. X-Powered-By: PHP/5.3.2-2
    111. Expires: Thu, 19 Nov 1981 08:52:00 GMT
    112. Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    113. Pragma: no-cache
    114. Content-Encoding: gzip
    115. ----------------------------------------------------------


    Hier mein WebRequest für den Login:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Function Req(ByVal Site As String, ByVal Post As String, ByVal Method As String, ByVal Host As String) As String
    2. Dim CookieCount As Double = 0
    3. Dim R As HttpWebRequest = HttpWebRequest.Create(Site)
    4. R.Method = Method
    5. R.ServicePoint.Expect100Continue = False
    6. R.CookieContainer = Cookies
    7. R.Host = Host
    8. R.MaximumAutomaticRedirections = 20
    9. R.AllowAutoRedirect = True
    10. R.Referer = ""
    11. R.Timeout = 10000
    12. R.ContentType = "application/x-www-form-urlencoded"
    13. R.ContentLength = Post.Length
    14. Dim writer As New IO.StreamWriter(R.GetRequestStream(), System.Text.Encoding.ASCII)
    15. writer.Write(Post)
    16. writer.Close()
    17. Dim Response As HttpWebResponse = DirectCast(R.GetResponse, HttpWebResponse)
    18. Response.Cookies = R.CookieContainer.GetCookies(R.RequestUri)
    19. Dim Reader As IO.StreamReader = New IO.StreamReader(Response.GetResponseStream)
    20. Dim SourceCode As String = Reader.ReadToEnd()
    21. Debug.Print(SourceCode)
    22. Reader.Close()
    23. For Each SetCookie As Cookie In Response.Cookies
    24. Debug.Print(SetCookie.Name)
    25. Next
    26. Return SourceCode
    27. End Function

    So setze ich den Login ein: (funktioniert auch einwandfrei, also Login wird auf jedenfall übernommen.)
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Dim var_movie2kcom_login As String = Req("http://www."google.de"/login.php?ua=login", "username" & User & "&password=" & Passwort, "POST", "www."google.de"")
    2. If var_movie2kcom_login.Contains("Add a tvshow") Then
    3. TextBox1.AppendText("Login auf "google.de" erfolgreich!")
    4. Else : TextBox1.AppendText("Login auf "google.de" fehlgeschlagen!")
    5. End If


    Und hier mein WebRequest für das Eintrag-Formular:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Function webrequest_movie2kcom(ByVal Site As String, ByVal Post As String, ByVal Method As String, ByVal Host As String) As String
    2. Dim R As HttpWebRequest = HttpWebRequest.Create(Site)
    3. R.Method = Method
    4. R.ServicePoint.Expect100Continue = True
    5. R.CookieContainer = Cookies
    6. R.Host = Host
    7. R.MaximumAutomaticRedirections = 200
    8. R.AllowAutoRedirect = True
    9. R.Referer = "http://www."google.de"/ui.php?ua=tvshow&do=add"
    10. R.Timeout = 10000
    11. R.Headers("useragent") = "Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"
    12. R.ContentType = "Content-Type: multipart/form-data; boundary=---------------------------" & TimeHash
    13. R.ContentLength = Post.Length
    14. Dim writer As New IO.StreamWriter(R.GetRequestStream(), System.Text.Encoding.ASCII)
    15. writer.Write(Post)
    16. writer.Close()
    17. Dim Response As HttpWebResponse = DirectCast(R.GetResponse, HttpWebResponse)
    18. Response.Cookies = R.CookieContainer.GetCookies(R.RequestUri)
    19. Dim Reader As IO.StreamReader = New IO.StreamReader(Response.GetResponseStream)
    20. Dim SourceCode As String = Reader.ReadToEnd()
    21. Debug.Print(SourceCode)
    22. Reader.Close()
    23. For Each SetCookie As Cookie In Response.Cookies
    24. Debug.Print(SetCookie.Name)
    25. Next
    26. Return SourceCode
    27. End Function

    So setze ich es ein:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Dim var_movie2kcom_add As String = webrequest_movie2kcom("http://www."google.de"/ui.php?ua=tvshow&do=add", boundary, "POST", "www."google.de"")

    Beide Requests nutzen den folgenden Cookiecontainer: (Da sollte ja kein Fehler liegen, Login funktioniert ja.)
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Private Cookies As System.Net.CookieContainer = New CookieContainer




    Ich bin so langsam wirklich ratlos, eine Fehlerquelle die ich mir vorstellen könnte wäre die im Original 15 stellige Zahl, die bei den Boundary-Posts vorkommt. Leider weiß ich nicht wie ich diese nachstelle. Aber ansonsten sollte soweit doch alles richtig sein?

    Ich hoffe es kann mir jemand helfen :)


    Vielen Dank im voraus,
    mewcrazy

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „mewcrazy“ ()

    Folgendermaßen bilden ich den Boundary-String. Mir ist klar das man das sicher optimieren kann, aber am Anfang mache ich so etwas lieber übersichtlicher damit ich Fehler vermeide.
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Dim boundary_title As String = "-----------------------------" & TimeHash
    2. Dim boundary_type As String = "Content-Disposition: form-data; name="
    3. Dim boundary As String = boundary_title & vbCrLf & boundary_type & """title""" & vbCrLf & vbCrLf & txt_title.Text & vbCrLf
    4. boundary &= boundary_title & vbCrLf & boundary_type & """season""" & vbCrLf & vbCrLf & combo_season.Text & vbCrLf
    5. boundary &= boundary_title & vbCrLf & boundary_type & """episode""" & vbCrLf & vbCrLf & txt_episode.Text & vbCrLf
    6. boundary &= boundary_title & vbCrLf & boundary_type & """language""" & vbCrLf & vbCrLf & txt_sprache.Text & vbCrLf
    7. boundary &= boundary_title & vbCrLf & boundary_type & """hoster""" & vbCrLf & vbCrLf & txt_hoster.Text & vbCrLf
    8. boundary &= boundary_title & vbCrLf & boundary_type & """link""" & vbCrLf & vbCrLf & txt_link.Text & vbCrLf
    9. boundary &= boundary_title & vbCrLf & boundary_type & """genre1""" & vbCrLf & vbCrLf & combo_genre1.Text & vbCrLf
    10. boundary &= boundary_title & vbCrLf & boundary_type & """genre2""" & vbCrLf & vbCrLf & combo_genre2.Text & vbCrLf
    11. boundary &= boundary_title & vbCrLf & boundary_type & """genre3""" & vbCrLf & vbCrLf & combo_genre3.Text & vbCrLf
    12. boundary &= boundary_title & vbCrLf & boundary_type & """genre4""" & vbCrLf & vbCrLf & combo_genre4.Text & vbCrLf
    13. boundary &= boundary_title & vbCrLf & boundary_type & """genre5""" & vbCrLf & vbCrLf & combo_genre5.Text & vbCrLf
    14. boundary &= boundary_title & vbCrLf & boundary_type & """thumbnail""" & vbCrLf & vbCrLf & "upload" & vbCrLf
    15. boundary &= boundary_title & vbCrLf & boundary_type & """thumnailfile""" & "; filename=""""" & vbCrLf & "Content-Type: application/octet-stream" & vbCrLf & vbCrLf & vbCrLf
    16. boundary &= boundary_title & vbCrLf & boundary_type & """thumbnaillink""" & vbCrLf & vbCrLf & txt_thumbnaillink.Text & vbCrLf
    17. boundary &= boundary_title & vbCrLf & boundary_type & """description""" & vbCrLf & vbCrLf & txt_beschreibung.Text & vbCrLf
    18. boundary &= boundary_title & vbCrLf & boundary_type & """duration""" & vbCrLf & vbCrLf & txt_duration.Text & vbCrLf
    19. boundary &= boundary_title & vbCrLf & boundary_type & """fsk""" & vbCrLf & vbCrLf & txt_fsk.Text & vbCrLf
    20. boundary &= boundary_title & vbCrLf & boundary_type & """countryyear""" & vbCrLf & vbCrLf & txt_countryyear.Text & vbCrLf
    21. boundary &= boundary_title & vbCrLf & boundary_type & """director""" & vbCrLf & vbCrLf & txt_director.Text & vbCrLf
    22. boundary &= boundary_title & vbCrLf & boundary_type & """actors""" & vbCrLf & vbCrLf & txt_actors.Text & vbCrLf
    23. boundary &= boundary_title & vbCrLf & boundary_type & """detail[1]""" & vbCrLf & vbCrLf & vbCrLf
    24. boundary &= boundary_title & vbCrLf & boundary_type & """detailtext[1]""" & vbCrLf & vbCrLf & vbCrLf
    25. boundary &= boundary_title & vbCrLf & boundary_type & """detail[2]""" & vbCrLf & vbCrLf & vbCrLf
    26. boundary &= boundary_title & vbCrLf & boundary_type & """detailtext[2]""" & vbCrLf & vbCrLf & vbCrLf
    27. boundary &= boundary_title & vbCrLf & boundary_type & """detail[3]""" & vbCrLf & vbCrLf & vbCrLf
    28. boundary &= boundary_title & vbCrLf & boundary_type & """detailtext[3]""" & vbCrLf & vbCrLf & vbCrLf
    29. boundary &= boundary_title & vbCrLf & boundary_type & """detail[4]""" & vbCrLf & vbCrLf & vbCrLf
    30. boundary &= boundary_title & vbCrLf & boundary_type & """detailtext[4]""" & vbCrLf & vbCrLf & vbCrLf
    31. boundary &= boundary_title & vbCrLf & boundary_type & """detail[5]""" & vbCrLf & vbCrLf & vbCrLf
    32. boundary &= boundary_title & vbCrLf & boundary_type & """detailtext[5]""" & vbCrLf & vbCrLf & vbCrLf
    33. boundary &= boundary_title & vbCrLf & boundary_type & """detail[6]""" & vbCrLf & vbCrLf & vbCrLf
    34. boundary &= boundary_title & vbCrLf & boundary_type & """detailtext[6]""" & vbCrLf & vbCrLf & vbCrLf
    35. boundary &= boundary_title & vbCrLf & boundary_type & """detail[7]""" & vbCrLf & vbCrLf & vbCrLf
    36. boundary &= boundary_title & vbCrLf & boundary_type & """detailtext[7]""" & vbCrLf & vbCrLf & vbCrLf
    37. boundary &= boundary_title & vbCrLf & boundary_type & """detail[8]""" & vbCrLf & vbCrLf & vbCrLf
    38. boundary &= boundary_title & vbCrLf & boundary_type & """detailtext[8]""" & vbCrLf & vbCrLf & vbCrLf
    39. boundary &= boundary_title & vbCrLf & boundary_type & """detail[9]""" & vbCrLf & vbCrLf & vbCrLf
    40. boundary &= boundary_title & vbCrLf & boundary_type & """detailtext[9]""" & vbCrLf & vbCrLf & vbCrLf
    41. boundary &= boundary_title & vbCrLf & boundary_type & """adtext""" & vbCrLf & vbCrLf & txt_adtext.Text & vbCrLf
    42. boundary &= boundary_title & vbCrLf & boundary_type & """adlink""" & vbCrLf & vbCrLf & txt_adlink.Text & vbCrLf
    43. boundary &= boundary_title & "--" & vbCrLf & vbCrLf & vbCrLf

    So sieht mein fertiger Boundary-String dann aus:
    Spoiler anzeigen

    Brainfuck-Quellcode

    1. -----------------------------634211421824535394
    2. Content-Disposition: form-data; name="title"
    3. Alle hassen Chris
    4. -----------------------------634211421824535394
    5. Content-Disposition: form-data; name="season"
    6. 01
    7. -----------------------------634211421824535394
    8. Content-Disposition: form-data; name="episode"
    9. 19
    10. -----------------------------634211421824535394
    11. Content-Disposition: form-data; name="language"
    12. 2
    13. -----------------------------634211421824535394
    14. Content-Disposition: form-data; name="hoster"
    15. 94
    16. -----------------------------634211421824535394
    17. Content-Disposition: form-data; name="link"
    18. http://www.filestage.to/watch/12ca2ac47e7d15f4bca55a6deb892d78/Alle.hassen.Chris.S01E19.Chris.hasst.Karate_randomanon.avi
    19. -----------------------------634211421824535394
    20. Content-Disposition: form-data; name="genre1"
    21. -----------------------------634211421824535394
    22. Content-Disposition: form-data; name="genre2"
    23. -----------------------------634211421824535394
    24. Content-Disposition: form-data; name="genre3"
    25. -----------------------------634211421824535394
    26. Content-Disposition: form-data; name="genre4"
    27. -----------------------------634211421824535394
    28. Content-Disposition: form-data; name="genre5"
    29. -----------------------------634211421824535394
    30. Content-Disposition: form-data; name="thumbnail"
    31. upload
    32. -----------------------------634211421824535394
    33. Content-Disposition: form-data; name="thumnailfile"; filename=""
    34. Content-Type: application/octet-stream
    35. -----------------------------634211421824535394
    36. Content-Disposition: form-data; name="thumbnaillink"
    37. -----------------------------634211421824535394
    38. Content-Disposition: form-data; name="description"
    39. -----------------------------634211421824535394
    40. Content-Disposition: form-data; name="duration"
    41. -----------------------------634211421824535394
    42. Content-Disposition: form-data; name="fsk"
    43. -----------------------------634211421824535394
    44. Content-Disposition: form-data; name="countryyear"
    45. -----------------------------634211421824535394
    46. Content-Disposition: form-data; name="director"
    47. -----------------------------634211421824535394
    48. Content-Disposition: form-data; name="actors"
    49. -----------------------------634211421824535394
    50. Content-Disposition: form-data; name="detail[1]"
    51. -----------------------------634211421824535394
    52. Content-Disposition: form-data; name="detailtext[1]"
    53. -----------------------------634211421824535394
    54. Content-Disposition: form-data; name="detail[2]"
    55. -----------------------------634211421824535394
    56. Content-Disposition: form-data; name="detailtext[2]"
    57. -----------------------------634211421824535394
    58. Content-Disposition: form-data; name="detail[3]"
    59. -----------------------------634211421824535394
    60. Content-Disposition: form-data; name="detailtext[3]"
    61. -----------------------------634211421824535394
    62. Content-Disposition: form-data; name="detail[4]"
    63. -----------------------------634211421824535394
    64. Content-Disposition: form-data; name="detailtext[4]"
    65. -----------------------------634211421824535394
    66. Content-Disposition: form-data; name="detail[5]"
    67. -----------------------------634211421824535394
    68. Content-Disposition: form-data; name="detailtext[5]"
    69. -----------------------------634211421824535394
    70. Content-Disposition: form-data; name="detail[6]"
    71. -----------------------------634211421824535394
    72. Content-Disposition: form-data; name="detailtext[6]"
    73. -----------------------------634211421824535394
    74. Content-Disposition: form-data; name="detail[7]"
    75. -----------------------------634211421824535394
    76. Content-Disposition: form-data; name="detailtext[7]"
    77. -----------------------------634211421824535394
    78. Content-Disposition: form-data; name="detail[8]"
    79. -----------------------------634211421824535394
    80. Content-Disposition: form-data; name="detailtext[8]"
    81. -----------------------------634211421824535394
    82. Content-Disposition: form-data; name="detail[9]"
    83. -----------------------------634211421824535394
    84. Content-Disposition: form-data; name="detailtext[9]"
    85. -----------------------------634211421824535394
    86. Content-Disposition: form-data; name="adtext"
    87. -----------------------------634211421824535394
    88. Content-Disposition: form-data; name="adlink"
    89. -----------------------------634211421824535394--
    90. Leerzeile
    91. Leerzeile (Habe gedacht an den beiden letzten Leerzeilen liegt es, aber hat leider keine Änderung gebracht.)


    Musste das in einen neuen Beitrag packen, da nur 15000 Zeichen pro Beitrag genutzt werden dürfen.
    Ach du machst mich auf den Rechtschreibfehler aufmerksam. Na das ist ja mal wieder ein VB-Paradise Niveau wie man es aus jedem 2. Thread kennt.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „mewcrazy“ ()

    mewcrazy schrieb:

    Na das ist ja mal wieder ein VB-Paradise Niveau wie man es aus jedem 2. Thread kennt

    *lach* aber Du musst zugeben die Rächtschreibung ist in diesem Forum auch wirklich unter aller , ehem, Kanone ist ...

    Ich hab mir Deinen Code mal näher angeschaut: viel Konstruktives kann ich zwar nicht ergänzen, aber damit Du Dich vollkommen verlassen fühlst:

    - beim Login-Code muss es "username=" & User heissen, sonst klappt der Login nie
    - die Prüfung auf Erfolg sollte per Contains("Logged in...") erfolgen, sonst auch falsch
    - statt Ascii.GetBytes sollte das Encoding per UTF8.GetBytes erfolgen, leider auch nicht der entscheidende Fehler
    - Deine Boundaries scheinen richtig zu sein, auch die "--" mehr bei den Params und am Ende der Nachricht
    - am Ende des Poststring kommt bei FF nur 1 vbCRLF

    Wenn man allerdings statt dem Live HTTP Header Addon einen Sniffer wie Net Monitor verwendet fällt auf, dass die Nachrichten unterschiedlich übertragen werden. Bei Verwendung von FF erscheinen die einzelnen Params als MultiPartEntry, während bei dem selbst erstellten HttpWebRequest die Params als PayLoad Lines erscheinen. Habe leider in der 1 Stunde in der ich mich damit beschäftigt habe noch nicht rausbekommen wo der Unterschied liegt bzw. wie er zustande kommt.

    Ausserdem ist die Länge der PostBytes bei FF und Deinem Code um über 100 Bytes verschieden, genauer hab ich noch nicht nachgeschaut.

    Meine Referenz für Post Boundaries war in der Vergangenheit immer dieser Artikel. Da Du den 15stelligen TimeHash angesprochen hattest: sollte eigentlich vollkommen egal sein, lt. RFC 1521 ist sogar irgendein eindeutiger String erlaubt, kann natürlich immer sein dass der Server eine Prüfung eingebaut hat.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Kangaroo“ ()

    Danke für deine Antwort,
    es funktioniert nun, allerdings habe ich mir eine HTTPPostRequest Class zur Hilfe genommen und meinen Login eingebaut + Cookiecontainer, nun funktioniert alles, und das sogar ohne das ich alle Variablen erwähnen muss wie es das Formular auf der Webseite macht.

    Hier die Klasse:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.IO
    2. Imports Microsoft.Win32
    3. Imports System.Runtime.CompilerServices
    4. Imports System.Net
    5. Imports System.Text
    6. Public Class Post
    7. Private m_PostArray As New ArrayList
    8. Private m_url As String
    9. Private m_timeout As Integer = 30000
    10. Public Sub New(ByVal url As String)
    11. m_url = url
    12. End Sub
    13. Public Sub New(ByVal url As String, ByVal Timeout As String)
    14. m_url = url
    15. End Sub
    16. Public Property Timeout As Integer
    17. Get
    18. Return m_timeout
    19. End Get
    20. Set(ByVal Value As Integer)
    21. m_timeout = Value
    22. End Set
    23. End Property
    24. Public Sub AddVariable(ByVal Variable As String, ByVal Value As String)
    25. Dim StringValueObj As New StringValue
    26. StringValueObj.Variable = Variable
    27. StringValueObj.Value = Value
    28. m_PostArray.Add(StringValueObj)
    29. End Sub
    30. Public Sub AddFile(ByVal Variable As String, ByVal File_Path As String)
    31. Dim FileValueObj As New FileValue
    32. FileValueObj.Variable = Variable
    33. FileValueObj.FilePath = File_Path
    34. m_PostArray.Add(FileValueObj)
    35. End Sub
    36. Public Function SubmitPost() As String
    37. Dim containsFile As Boolean = False
    38. Dim request As HttpWebRequest = DirectCast(WebRequest.Create(m_url), HttpWebRequest)
    39. request.CookieContainer = Cookies
    40. Dim boundary As String = "----------------------------" &
    41. DateTime.Now.Ticks.ToString("x")
    42. request.Method = "POST"
    43. request.KeepAlive = True
    44. 'request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"
    45. request.Timeout = m_timeout
    46. 'request.Headers.Add("Accept-Language", "vb,en-us;q=0.7,en;q=0.3")
    47. request.ContentType = "multipart/form-data; boundary=" & boundary
    48. request.Credentials = System.Net.CredentialCache.DefaultCredentials
    49. 'request.PreAuthenticate = False
    50. Dim builder As New StringBuilder()
    51. Dim builder2 As New StringBuilder
    52. For z As Integer = 0 To m_PostArray.Count - 1
    53. If TypeOf (m_PostArray(z)) Is StringValue Then
    54. builder.Append("--" & boundary) 'ALWAYS KEEP THE two -- otherwise boundary will not be correct aka dont change this line
    55. builder.Append(vbCrLf)
    56. builder.Append("Content-Disposition: form-data; name=""" &
    57. m_PostArray(z).Variable & """" & vbCrLf)
    58. builder.Append(vbCrLf)
    59. builder.Append(m_PostArray(z).Value)
    60. builder.Append(vbCrLf)
    61. builder2.Append(m_PostArray(z).Variable & "=" &
    62. m_PostArray(z).Value & "&")
    63. End If
    64. If TypeOf (m_PostArray(z)) Is FileValue Then
    65. containsFile = True
    66. builder.Append("--" & boundary)
    67. builder.Append(vbCrLf)
    68. builder.Append("Content-Disposition: form-data; name=""" &
    69. m_PostArray(z).Variable & """;filename=""" &
    70. m_PostArray(z).FileName & """" & vbCrLf)
    71. builder.Append("Content-Type: " & m_PostArray(z).ContentType &
    72. vbCrLf)
    73. builder.Append(vbCrLf)
    74. builder.Append(Encoding.UTF8.GetString(m_PostArray(z).FileData))
    75. 'builder.Append(m_PostArray(z).FileData)
    76. builder.Append(vbCrLf)
    77. End If
    78. Next
    79. builder.Append("--" & boundary & "--" & vbCrLf)
    80. builder2 = builder2.Remove(builder2.Length - 1, 1)
    81. Dim bytes As Byte()
    82. If containsFile = True Then
    83. bytes = Encoding.UTF8.GetBytes(builder.ToString)
    84. Else
    85. request.ContentType = "application/x-www-form-urlencoded"
    86. bytes = Encoding.UTF8.GetBytes(builder2.ToString)
    87. End If
    88. request.ContentLength = bytes.Length
    89. Dim ReturnString As String = ""
    90. Using stream As Stream =
    91. request.GetRequestStream
    92. stream.Write(bytes, 0,
    93. bytes.Length)
    94. stream.Flush()
    95. stream.Close()
    96. Try
    97. Using response As WebResponse = request.GetResponse
    98. Using reader As StreamReader = New StreamReader(response.GetResponseStream)
    99. ReturnString = reader.ReadToEnd
    100. End Using
    101. End Using
    102. Catch ex As Exception
    103. ReturnString = "ERROR"
    104. End Try
    105. End Using
    106. Return ReturnString
    107. End Function
    108. Private Class StringValue
    109. Private m_Variable As String
    110. Private m_Value As String
    111. Public Property Variable As String
    112. Get
    113. Return m_Variable
    114. End Get
    115. Set(ByVal Value As String)
    116. m_Variable = Value
    117. End Set
    118. End Property
    119. Public Property Value As String
    120. Get
    121. Return m_Value
    122. End Get
    123. Set(ByVal Value As String)
    124. m_Value = Value
    125. End Set
    126. End Property
    127. End Class
    128. Private Class FileValue
    129. Private m_Variable As String
    130. Private m_FilePath As String
    131. Private m_FileData As Byte()
    132. Private m_FileName As String
    133. Private m_ContentType As String
    134. Public Property Variable As String
    135. Get
    136. Return m_Variable
    137. End Get
    138. Set(ByVal Value As String)
    139. m_Variable = Value
    140. End Set
    141. End Property
    142. Public Property FilePath As String
    143. Get
    144. Return m_FilePath
    145. End Get
    146. Set(ByVal Value As String)
    147. m_FilePath = Value
    148. If My.Computer.FileSystem.FileExists(m_FilePath) = True Then
    149. 'Load data of the file
    150. Using stream As FileStream = New FileStream(m_FilePath, FileMode.Open, FileAccess.Read)
    151. Dim array As Byte() = New Byte((CInt((stream.Length - 1)) + 1) - 1) {}
    152. stream.Read(array, 0, array.Length)
    153. m_FileData = array
    154. End Using
    155. 'Get Name of File with extension
    156. m_FileName =
    157. Split(m_FilePath, "\")(Split(m_FilePath, "\").Length - 1)
    158. 'Get Content Type
    159. m_ContentType = GetMIMEType(m_FilePath, False)
    160. End If
    161. End Set
    162. End Property
    163. Public ReadOnly Property FileData As Byte()
    164. Get
    165. Return m_FileData
    166. End Get
    167. End Property
    168. Public ReadOnly Property FileName As String
    169. Get
    170. Return m_FileName
    171. End Get
    172. End Property
    173. Public ReadOnly Property ContentType As String
    174. Get
    175. Return m_ContentType
    176. End Get
    177. End Property
    178. Private Shared Function GetMIMEType(ByVal szFileName As String, ByVal forceDatabase As Boolean) As String
    179. Dim str2 As String = Nothing
    180. Dim extension As String = Path.GetExtension(szFileName)
    181. Dim objectValue As Object = Nothing
    182. If Not forceDatabase Then
    183. Dim key As RegistryKey =
    184. Registry.ClassesRoot.OpenSubKey(extension)
    185. If (Not key Is Nothing) Then
    186. objectValue =
    187. RuntimeHelpers.GetObjectValue(key.GetValue("Content Type"))
    188. key.Close()
    189. End If
    190. End If
    191. If (forceDatabase AndAlso (objectValue Is Nothing)) Then
    192. Return objectValue.ToString
    193. End If
    194. Dim key2 As RegistryKey =
    195. Registry.ClassesRoot.OpenSubKey("MIME\Database\Content Type")
    196. Dim str4 As String
    197. For Each str4 In
    198. key2.GetSubKeyNames
    199. Dim key3 As RegistryKey =
    200. key2.OpenSubKey(str4)
    201. Dim obj3 As Object =
    202. RuntimeHelpers.GetObjectValue(key3.GetValue("Extension"))
    203. If ((Not obj3 Is Nothing) AndAlso (obj3.ToString = extension)) Then
    204. str2 = str4
    205. Exit For
    206. End If
    207. key3.Close()
    208. Next
    209. key2.Close()
    210. Return str2
    211. End Function
    212. End Class
    213. End Class