开发者

Help needed on Uploading Files in windows mobile

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


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));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜