share-online.biz Upload per API

  • VB.NET
  • .NET 4.5

    share-online.biz Upload per API

    Hallo zusammen,

    ich versuche per API eine Datei bei share-online.biz hochzuladen.

    Als Informationsgrundlage dient mir die Beschreibung der API von share-online.biz/uploadapi/


    Request to: share-online.biz/upv3_session.php

    Required Vars:
    [username] account username
    [password] account password
    Response: SESSIONNAME;UPLOADSERVER/SKRIPT.PHP
    Example: GW63P9DEC;server/upv3.php


    Die Sessiondaten bekomme ich im Moment mit der Funktion:

    VB.NET-Quellcode

    1. Dim username = "username"
    2. Dim password = "password"
    3. Dim Request As HttpWebRequest = CType(WebRequest.Create("http://www.share-online.biz/upv3_session.php"), HttpWebRequest)
    4. Request.Method = "POST"
    5. Request.ContentType = "application/x-www-form-urlencoded"
    6. Dim Post As String = "&username=" & username & "&password=" & password
    7. Dim byteArray() As Byte = Encoding.UTF8.GetBytes(Post)
    8. Request.ContentLength = byteArray.Length
    9. Dim DataStream As Stream = Request.GetRequestStream()
    10. DataStream.Write(byteArray, 0, byteArray.Length)
    11. DataStream.Close()
    12. Dim Response As HttpWebResponse = Request.GetResponse()
    13. DataStream = Response.GetResponseStream()
    14. Dim reader As New StreamReader(DataStream)
    15. Dim ServerResponse As String = reader.ReadToEnd()
    16. reader.Close()
    17. DataStream.Close()
    18. Response.Close()
    19. Dim value As String = ServerResponse
    20. Dim words() As String = value.Split(";")
    21. sessionname = words(0)
    22. uploadserver = words(1)


    Jetzt bekomme ich diese Daten allerdings nicht für den Upload weiterverarbeitet.


    Request to: server/upv3.php

    Required Vars:
    [username] account username
    [password] account password
    [upload_session] upload session name from step 1
    [chunk_no] set to "1"
    [chunk_number] set to "1"
    [filesize] filesize of current file in bytes
    [fn] filedata (in HTTP forms known as type="file")
    [finalize] set to "1"

    Response: DOWNLOAD-URL;FILESIZE;MD5

    Example: share-online.biz/dl/HJD74ZDM1;
    6547231;316508123e89909723fe95945caf00a5
    (linebreak only in example!)


    Habe beispielhaft den Code von der Session abgeändert, aber da wird wohl irgendwo der Fehler liegen:

    VB.NET-Quellcode

    1. Dim sessionname As String = "", uploadserver As String = ""
    2. Rückgabe(sessionname, uploadserver)
    3. Dim username = "username"
    4. Dim password = "password"
    5. Dim chunk_no = 1
    6. Dim chunk_number = 1
    7. Dim filesize = "772480"
    8. Dim fn = "C:\Jellyfish.zip"
    9. Dim finalize = 1
    10. Dim Request As HttpWebRequest = CType(WebRequest.Create("http://" & uploadserver), HttpWebRequest)
    11. Request.Method = "POST"
    12. Request.ContentType = "application/x-www-form-urlencoded"
    13. Dim Post As String = "&username=" & username & "&password=" & password & "&upload_session=" & sessionname & "&chunk_no" = chunk_no & "&chunk_number=" & chunk_number _
    14. & "&filesize=" & filesize & "&fn=" & fn & "&finalize=" & finalize
    15. Dim byteArray() As Byte = Encoding.UTF8.GetBytes(Post)
    16. Request.ContentLength = byteArray.Length
    17. Dim DataStream As Stream = Request.GetRequestStream()
    18. DataStream.Write(byteArray, 0, byteArray.Length)
    19. DataStream.Close()
    20. Dim Response As HttpWebResponse = Request.GetResponse()
    21. DataStream = Response.GetResponseStream()
    22. Dim reader As New StreamReader(DataStream)
    23. Dim ServerResponse As String = reader.ReadToEnd()
    24. reader.Close()
    25. DataStream.Close()
    26. Response.Close()
    27. MsgBox(ServerResponse)


    Damit bekomme ich folgende Fehlermeldung:


    Der Remoteserver hat einen Fehler zurückgegeben: (415) Unsupported Media Type.


    Der HTML-Code funktioniert, bekomme den aber nicht auf VB.net umgemünzt:

    HTML-Quellcode

    1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    4. <head>
    5. <title>UPLOAD-API</title>
    6. </head>
    7. <body>
    8. <form enctype="multipart/form-data" action="http://server/upv3.php" method="POST">
    9. <table>
    10. <tr><td>Uploadfile:</td><td><input name="fn" type="file" />
    11. <input type="submit" value="Upload File" /></td></tr>
    12. <tr><td>Session:</td><td><input type="text" name="upload_session" value="" /></td></tr>
    13. <tr><td>Chunk_no:</td><td><input type="text" name="chunk_no" value="" /></td></tr>
    14. <tr><td>Chunk_number:</td><td><input type="text" name="chunk_number" value="" /></td></tr>
    15. <tr><td>Filesize:</td><td><input type="text" name="filesize" value="" /></td></tr>
    16. <tr><td>Finalize:</td><td><input type="text" name="finalize" value="" /></td></tr>
    17. <tr><td>Username</td><td><input type="text" name="username" value="" /></td></tr>
    18. <tr><td>Password</td><td><input type="text" name="password" value="" /></td></tr>
    19. <tr><td><input type="submit" value="Upload File" /></td></tr>
    20. </table>
    21. </form>
    22. </body>
    23. </html>


    Was muss ich wie abändern, damit das klappt oder bin ich auf dem völlig falschen Dampfer?

    Vielen Dank im Voraus!