2013-03-13 3 views
-1

API 문서를 사용하여 Rapidshare에 업로드하려고합니다. 이미 많은 기사를 보았지만 여전히 "완료"할 수 없었습니다. 현재 나는 다음과 같은 응답 오류가 계속은 : Rapidshare API 업로드 파일

ERROR: Subroutine invalid. (b6ba5d82)

나는 다음과 같은 문서 사용 :

http://images.rapidshare.com/apidoc.txt

을 또한 I에 유래에서 발견 예를 들어 사용 :

Upload files with HTTPWebrequest (multipart/form-data)

다음 코드를 사용하고 있습니다 :

Sub Main 
    Dim freeurl As String = "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver" 
    Dim req As WebRequest = WebRequest.Create(freeurl) 
    Dim response = req.GetResponse().GetResponseStream() 
    Dim reader As New StreamReader(response) 
    Dim nextfreeserver = reader.ReadToEnd() 
    req = Nothing 
    response = Nothing 
    reader= Nothing 

    Dim login As String = "********" 
    Dim password As String = "********" 
    Dim filename As string = "test12345.txt" 
    Dim filepath = "C:\Users\Public\Documents\" & filename 

    Dim uploadurl As String = "https://rs" & nextfreeserver & ".rapidshare.com/cgi-bin/rsapi.cgi?sub=upload" 
    uploadurl = uploadurl & "&login=" & login & "&password=" & password & "&filename" & filename & "&filecontent=" & filepath 



    Dim nvc As NameValueCollection = new NameValueCollection() 

    nvc.Add("sub", "upload") 
    nvc.Add("login", login) 
    nvc.Add("password", password) 

    Dim resp As String = "" 
    resp = HttpUploadFile("https://rs" & nextfreeserver & ".rapidshare.com/cgi-bin/rsapi.cgi", filepath, "filecontent", "application/octet-stream", nvc) 

End Sub 

Public Shared Function HttpUploadFile(url As String, file As String, paramName As String, contentType As String, nvc As NameValueCollection) As string 

    Dim boundary As String = "---------------------------" & DateTime.Now.Ticks.ToString("x") 
    Dim boundarybytes As Byte() = System.Text.Encoding.ASCII.GetBytes(vbCr & vbLf & "--" & boundary & vbCr & vbLf) 

    Dim wr As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest) 
    wr.ContentType = "multipart/form-data; boundary=" & boundary 
    wr.Method = "POST" 
    wr.KeepAlive = True 
    wr.Credentials = System.Net.CredentialCache.DefaultCredentials 

    Dim rs As Stream = wr.GetRequestStream() 

    Dim formdataTemplate As String = "Content-Disposition: form-data; name=""{0}""" & vbCr & vbLf & vbCr & vbLf & "{1}" 
    For Each key As String In nvc.Keys 
     rs.Write(boundarybytes, 0, boundarybytes.Length) 
     Dim formitem As String = String.Format(formdataTemplate, key, nvc(key)) 
     Dim formitembytes As Byte() = System.Text.Encoding.UTF8.GetBytes(formitem) 
     rs.Write(formitembytes, 0, formitembytes.Length) 
    Next 
    rs.Write(boundarybytes, 0, boundarybytes.Length) 

    Dim headerTemplate As String = "Content-Disposition: form-data; name=""{0}""; filename=""{1}""" & vbCr & vbLf & "Content-Type: {2}" & vbCr & vbLf & vbCr & vbLf 
    Dim header As String = String.Format(headerTemplate, paramName, file, contentType) 
    Dim headerbytes As Byte() = System.Text.Encoding.UTF8.GetBytes(header) 
    rs.Write(headerbytes, 0, headerbytes.Length) 

    Dim fileStream As New FileStream(file, FileMode.Open, FileAccess.Read) 
    Dim buffer As Byte() = New Byte(4095) {} 
    Dim bytesRead As Integer = 0 
    While (InlineAssignHelper(bytesRead, fileStream.Read(buffer, 0, buffer.Length))) <> 0 
     rs.Write(buffer, 0, bytesRead) 
    End While 
    fileStream.Close() 

    Dim trailer As Byte() = System.Text.Encoding.ASCII.GetBytes(vbCr & vbLf & "--" & boundary & "--" & vbCr & vbLf) 
    rs.Write(trailer, 0, trailer.Length) 
    rs.Close() 

    Dim wresp As WebResponse = Nothing 
    Try 
     wresp = wr.GetResponse() 

     Dim stream2 As Stream = wresp.GetResponseStream() 
     Dim reader2 As New StreamReader(stream2) 
     return reader2.ReadToEnd() 


     If wresp IsNot Nothing Then 
      wresp.Close() 
      wresp = Nothing 
     End If 
    Finally 
     wr = Nothing 
    End Try 
End Function  

Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, value As T) As T 
    target = value 
    Return value 
End Function 

답변

0

URL 자체에 데이터를 넣지 않아야하므로 작동하지 않습니다. Rapidshare는 업로드의 기본 URL은 다음과 같습니다

https://rs + nextfreeserver + .rapidshare.com/cgi-bin/rsapi.cgi 

다른 모든 물건은 다중 형식 자체에 넣어해야합니다.

nextserver=$(\ 
    curl http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver) 

그리고 : : 파일의 업로드시 발생하는 모든 것을 볼 수있는 --verbose 또는 --trace 스위치

curl -F sub=upload \ 
    -F filecontent="@foo;filename=foo" \ 
    -F login=myname -F password=mypassword \ 
    https://rs$nextserver.rapidshare.com/cgi-bin/rsapi.cgi 

을 (

는 쉘에서 시도 더 많은 정보를 정기적으로 얻으려면 송수신 헤더, 게시 된 데이터 등). 디버깅 목적으로도 편리합니다.