在Windows Mobile中上传文件时需要帮助

时间:2009-11-13 06:43:08

标签: c# asp.net windows-mobile cgi

我的桌面上运行了一个桌面应用程序。 我需要将文件路径发送到在服务器上运行的CGI脚本。 CGI脚本获取文件路径并从我的机器上传内容。

我尝试通过httppost方法发送文件路径;它不起作用 - 任何人都可以建议我怎么做..我尝试过的方法是:

 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());

和我尝试的另一种方式是:

 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();

两种方式都不起作用。

但是下面回答的代码在winmo中的桌面上运行它告诉WebClient没有表现出来...... 请告诉我们如何将数据发送到windows mobile中服务器中的脚本

1 个答案:

答案 0 :(得分:1)

这就像获取WebClient参数一样简单吗? (您似乎将文件路径作为url传递,而不是使用编码):

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