Rapidshare API with PowerShell

爱⌒轻易说出口 提交于 2019-12-20 06:39:31

问题


$FreeUploadServer = Invoke-RestMethod -Uri "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver"
Invoke-RestMethod -Uri "http://rs$FreeUploadServer.rapidshare.com/cgi-bin/rsapi.cgi?sub=upload&login=43533592&password=password&filecontent=C:\libs\test.txt" 

I have no clue why that isnt working, its something to do with the filecontent parameter but i have read the entire documentation about the API and i cant figure it out.

API Documentation


回答1:


Make sure you use the -Method Post parameter/arg combo on the second Invoke-RestMethod call. Also, take a look at this SO response to a similar question about using CURL. After looking at the question and answer, it appears that RapidShare requires filling in POST form fields. In this case you need to specify the -Body parameter. I think you'll use a PowerShell hashtable where each entry corresponds to a form field name/value pair. Looks like the one field needed is the filecontent field. Presumably the value is the file's contents.

Also, when you use POST, you'll have to convert the GET query parameters to POST form fields e.g.:

$url = "http://rs$FreeUploadServer.rapidshare.com/cgi-bin/rsapi.cgi"
$fields = @{sub='upload';login='43533592';password='password';filename='test.txt';
            filecontent=([IO.File]::ReadAllText('c:\libs\test.txt'))}

Invoke-RestMethod -Uri $url -Body $fields -Method Post

If [IO.File]::ReadAlltext() doesn't cut it perhaps try [IO.File]::ReadAllBytes() instead.




回答2:


Turns out there is a tiny section in the API Documentation that says if you use the POST method all parameters need to be passed in the body. I wrote a function that uploads to RapidShare in PowerShell, i hope this helps people in the future cause this was VERY annoying.

function Upload-RapidShare([string]$File,[string]$Name)
{
     $FreeUploadServer = Invoke-RestMethod -Uri "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver"
     Invoke-RestMethod "http://rs$FreeUploadServer.rapidshare.com/cgi-bin/rsapi.cgi" -Body  "sub=upload&login=USERNAME&password=PASSWORD&filename=$Name&filecontent=$File" -Method Post
}


来源:https://stackoverflow.com/questions/12251965/rapidshare-api-with-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!