I am trying to upload a image to a website by using a WebRequest in C#.
The problem is that the response that I get returns an error.
I would appreciate it if someone could help me find what I did wrong.
the error:
Notice: Undefined index: qqfile in /var/www/2n4u/pomf/new/qqFileUploader.php on line 71
{"error":"File is empty.","uploadName":null}
and my code:
scrot.Save("pomfse.png", ImageFormat.Png);
FileInfo fi = new FileInfo("pomfse.png");
string qquid = "qquid=" + Guid.NewGuid();
string qqtotalfilesize = "&qqtotalfilesize=" + Convert.ToString(fi.Length);
string qqfile = "&qqfile=pomfse.png";
string url = @"http://www.pomf.se/new/up.php?" + qquid + qqtotalfilesize + qqfile;
System.Net.WebRequest req = WebRequest.CreateHttp(url);
req.ContentType = "multipart/form-data";
req.Method = "POST";
byte[] bytes = (byte[])new ImageConverter().ConvertTo(scrot, typeof(byte[]));
req.ContentLength = bytes.Length;
Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
WebResponse resp = req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
string response = sr.ReadToEnd().Trim();
EDIT: Seems like this question was marked as a duplicate, but the duplicate contains information for the PHP error, but there is no answer that can help me with the problem in C#.