I'm tring to write a little program to download a PDF from a newspaper website that requires a login. I'm using this library found on stackoverflow: http://pastebin.com/RPNU39vF
And I call it with this code:
private void backupFunzionante()
{
String postData = "log=MYEMAIL@gmail.com&pwd=MYPASSWORD";
myWeb.RequestManager manager = new myWeb.RequestManager();
String uri = "http://shop.ilfattoquotidiano.it/login/?action=login";
HttpWebResponse response;
response = manager.SendPOSTRequest(uri, postData, null, null, true);
String strResp = response.StatusCode.ToString();
label1.Text += "###";
Uri pdfUrl = new Uri("http://pdf.ilfattoquotidiano.it/openpdf/?n=20120927");
response = manager.SendPOSTRequest("http://pdf.ilfattoquotidiano.it/openpdf/?n=20120927", "", null, null, true);
long size = response.ContentLength;
Stream downloadStream = response.GetResponseStream();
using (Stream file = File.OpenWrite("C:\\f.pdf"))
{
CopyStream(downloadStream, file);
}
}
public static void CopyStream(Stream input, Stream output)
{
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, len);
}
}
This code works perfectly if run under .NET, while it returns a empty file if called under mono.
I think the problem should be in http post request, because size in long size = response.ContentLength; is zero.
Why there is this difference between the two executables? What I can do to have a fully portable application (I would like to use it also under linux because it is my primary OS)
Thank you for your help.