[Mono-list] HTTP file download

giancarlogiesa giancarlogiesa at gmail.com
Fri Apr 24 17:05:11 EDT 2009


Hello,

is possible with C# / Mono download a file from an HTTP server ?
if yes, how ?

my code is this:
------------------------------------
    private string SocketSendReceive(string url){
		int i=0;
		while(i<url.Length && url[i]!='/'){
			i++;
		}
		string server=url.Substring(0,i);
		string request = "GET "+url.Substring(i)+" HTTP/1.1\r\nHost: " + server +
"\r\nConnection: Close\r\n\r\n";
        Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
        Byte[] bytesReceived = new Byte[1024];
        Socket s = ConnectSocket(server, 80);
        if (s == null){
            return ("Connection failed");
		}
        s.Send(bytesSent, bytesSent.Length, 0);  
			
        int bytes = 0;
        string page = null;
        do {
            bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
            page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
        }while (bytes > 0);
		i=2;
		while(i<page.Length && !(page[i-2]=='\n' && page[i]=='\n')){
			i++;
		}
		if(page[page.Length-1]=='\n'){
			return page.Substring(++i,page.Length-i-1);
		}
		return page.Substring(++i);
    }
--------------------------------------
it return the correct value of a web-page, but if i try to download a zip
file ( my target ), it will get the file in the string, but is not the
perfect same and the unzip will not work

so my question is what can i do?
-- 
View this message in context: http://www.nabble.com/HTTP-file-download-tp23224875p23224875.html
Sent from the Mono - General mailing list archive at Nabble.com.



More information about the Mono-list mailing list