views:

73

answers:

1

I have an desktop application running on my desktop. I need to send the file path to the CGI script running at server. CGI script taks the file path and upload the contents from my machine.

I tried to send the file path through httppost method; it is not working - can any one suggest me how to do.. methods I have tried are:

 WebClient upload = new WebClient();

        NetworkCredential nc = new NetworkCredential("test", "admin");

        Uri URL = new Uri("http:\\10.10.21.55\\cgi-bin\\file_upload.cgi");
        upload.Credentials = nc;
        byte [] data = upload.UploadFile(filepath, "c:/Data.txt");
        Console.WriteLine(data.ToString());

and the other way I tried is:

 byte[] buf = new byte[8192];
        // prepare the web page we will be asking for
        HttpWebRequest request = (HttpWebRequest)
        WebRequest.Create("http://10.10.21.55/cgi-bin/file_upload.cgi");
        WebResponse rsp = null;

        request.Method = "POST";
        request.ContentType = "text/xml";
        StreamWriter writer = new StreamWriter(request.GetRequestStream());

        writer.WriteLine("hi hiw are you");
        writer.Close();

both ways are not working.

but the below answered code works in desktop in winmo its telling WebClient not implimented... please tell how to send data to script present in server in windows mobile

+1  A: 

Is this as simple as getting the WebClient parameters right? (you seem to be passing in file-path as the url, and not using the encoding):

using(WebClient upload = new WebClient()) {
    NetworkCredential nc = new NetworkCredential("test", "admin");
    upload.Credentials = nc;
    byte[] data = upload.UploadFile(
        @"http//10.10.21.55/cgi-bin/file_upload.cgi", @"c:\Data.txt");
    Console.WriteLine(upload.Encoding.GetString(data));
}
Marc Gravell
Yup marc, your code works.. small changes i does are, i didn't set any credentials for server..
Shadow
Marc i agree with you.. i got one more prob..WebClient is not supported in windows mobile...how can i achieve the same operation in windows mobile
Shadow