Click here to Skip to main content
16,017,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, please can u advice me with upload on server with your method using webrequests? How i can create stringBuilder on another server? and why its return this?
"
<h1>Software error:</h1>
<pre>Malformed multipart POST
</pre>
<p>
For help, please send mail to the webmaster (<a href="mailto:webmaster@ulozto.cz">webmaster@ulozto.cz</a>), giving this error message
and the time and date of the error.

</p>
"

my code of program :
"
public string QUploadToUlozto(string FilePath, string username,
string password, int AccountType)
{
FileSystemInfo _file = new FileInfo(FilePath);
DateTime dateTime2 = DateTime.Now;
long l2 = dateTime2.Ticks;
string s1 = "----------" + l2.ToString("x");
System.Net.HttpWebRequest httpWebRequest = GetWebrequest(s1);
using (System.IO.FileStream fileStream = new FileStream(_file.FullName,
FileMode.Open, FileAccess.Read, FileShare.Read))
{//Set Headers for Uploading
byte[] bArr1 = Encoding.ASCII.GetBytes("\r\n--" + s1 + "\r\n");
string s2 = GetRequestMessage(s1, _file.Name, username, password, AccountType);
byte[] bArr2 = Encoding.UTF8.GetBytes(s2);
Stream memStream = new MemoryStream();
memStream.Write(bArr1, 0, bArr1.Length);
memStream.Write(bArr2, 0, bArr2.Length);
byte[] buffer = new byte[1024];
int bytesRead = 0;//Read File into memStream.
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
memStream.Write(buffer, 0, bytesRead);

}
httpWebRequest.ContentLength = memStream.Length;
fileStream.Close();

Stream requestStream = httpWebRequest.GetRequestStream();
//Send File from memStream to Rapidshare.com
memStream.Position = 0;
byte[] tempBuffer = new byte[memStream.Length];
memStream.Read(tempBuffer, 0, tempBuffer.Length);
memStream.Close();
requestStream.Write(tempBuffer, 0, tempBuffer.Length);
requestStream.Close();
}
string tm = "";
using (Stream stream = httpWebRequest.GetResponse().GetResponseStream())
using (StreamReader streamReader = new StreamReader(stream))
{
tm = streamReader.ReadToEnd();

}//Get Response from Rapidshare and Return the Links.
return tm;
}

private string GetRequestMessage(string boundary, string FName,
string username, string password, int AccountType)
{
System.Text.StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("--");
stringBuilder.Append(boundary);
stringBuilder.Append("\r\n");
stringBuilder.Append("Content-Disposition: form-data; name=\"toolmode2\"");
stringBuilder.Append("\r\n");
stringBuilder.Append("\r\n");
stringBuilder.Append("1");
stringBuilder.Append("\r\n");
stringBuilder.Append(boundary);
stringBuilder.Append("\r\n");
if (AccountType != 0)//Free User
{
}//else if Free User
//File Name

stringBuilder.Append(boundary);
stringBuilder.Append("\r\n");
stringBuilder.Append("Content-Disposition: form-data; name=\"");
stringBuilder.Append("upfile_0");
stringBuilder.Append("\"; filename=\"");
stringBuilder.Append(FName);
stringBuilder.Append("\"");
stringBuilder.Append("\r\n");
//File Type
stringBuilder.Append("Content-Type: ");
stringBuilder.Append("multipart/form-data");
stringBuilder.Append("\r\n");
stringBuilder.Append("Content-Transfer-Encoding: ");
stringBuilder.Append("binary");
stringBuilder.Append("\r\n");
stringBuilder.Append("\r\n");

return stringBuilder.ToString();
}

private CookieContainer _cockies = new CookieContainer();
private HttpWebRequest GetWebrequest(string boundary)
{//Prepare for Uploading
WebClient wc = new WebClient();
System.Uri uri = new Uri("http://up.uloz.to/ul/upload.cgi?tmp_sid=" + "4b8952990b8b1518ab1729728394bh29" + "&user_id=0&host=uloz.to");

System.Net.HttpWebRequest httpWebRequest = (
System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
httpWebRequest.CookieContainer = _cockies;//Set Cookies for rapidshare
httpWebRequest.ContentType = "multipart/form-data; boundary=" + boundary;
//Set Fake userAgent exactly like Rapidshare Manager
httpWebRequest.UserAgent = "MultiloadUploader";
//Set Fake Referer
httpWebRequest.Referer = "http://uloz.to/";
httpWebRequest.Method = "POST";
httpWebRequest.KeepAlive = true;
httpWebRequest.Timeout = -1;
httpWebRequest.Headers.Add("Accept-Charset", "iSO-8859-1,utf-8;q=0.7,*;q=0.7");
httpWebRequest.Headers.Add("Accept-Encoding", "identity");
httpWebRequest.Headers.Add("Accept-Language", "de-de;q=0.5,en;q=0.3");
return httpWebRequest;
}
"

sorry for my bad english and thanx :)
Posted
Updated 6-Jan-10 20:08pm
v2

wrote:
with your method


What method ? Who are you talking to ? If this relates to an article, the author is not going to necessarily see it, and a forum is provided under the article for you to contact him/her.
 
Share this answer
 
emm sorry...my bad, original code is here : Simple Upload File to Rapidshare Account Method using C#[^] and I am desperate, because I dont know how make it, or know someone a better code for upload to different servers? thanks ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900