I'm currently trying to port my Perl upload script to C#, but I'm not quite familiar with the language and can't get it working. I've tried it a long time but nothing seems to work. I appreciate any help. :)
Perl version:
#!/usr/bin/perl -w
use strict;
use warnings;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request::Common;
my ($user, $pass, $type, $fileName);
# This chapter sets some vars and parses some vars.
$/ = undef;
$SIG{PIPE} = 'IGNORE';
$fileName = $ARGV[0] || die "Syntax: $0 <filename to upload> <free|prem|col> [login] [password]\n";
$type = $ARGV[1] || "";
$user = $ARGV[2] || "";
$pass = $ARGV[3] || "";
# RapidShare API Documentation @ http://images.rapidshare.com/apidoc.txt
my $nextuploadserver = get('http://rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver');
die 'nextuploadserver broken' if $nextuploadserver !~ /^\d+$/;
print 'nextuploadserver:' . $nextuploadserver . "\n";
my $userAgent = LWP::UserAgent->new();
my $request = POST 'http://rs' . $nextuploadserver . '.rapidshare.com/cgi-bin/rsapi.cgi',
Content_Type => 'form-data',
Content => [
sub => 'upload',
login => $user,
password => $pass,
filename => $fileName,
filecontent => [$fileName],
];
my $response = $userAgent->request($request);
die 'fucked up' if $response->is_error();
print $response->content . "\n";
C#, that's what I have tried:
WebClient wc = new WebClient();
wc.Headers["Content-Type"] = "form-data";
System.Text.UTF8Encoding utf8 = new System.Text.UTF8Encoding();
string a = utf8.GetString(
wc.UploadData(
@"https://rs702l3.rapidshare.com/
cgi-bin/rsapi.cgi", "POST", System.Text.Encoding.UTF8.GetBytes(
"sub=upload&login=XXXX&password=XXXX&folder=0&filename=Test.jpg
&filecontent=" + utf8.GetString(File.ReadAllBytes(@"D:\Test.jpg")))));
Console.WriteLine("Test: " + a);
P.S.: If anyone is looking for a Rapidshare uplaod script which is working, you are free to use mine as I posted it in the thread. :)