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

发布于 2024-08-11 05:24:57 字数 1110 浏览 2 评论 0原文

我的桌面上运行着一个桌面应用程序。 我需要将文件路径发送到服务器上运行的 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服务器中的脚本

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情深如许 2024-08-18 05:24:57

这就像正确获取 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));
}

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));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文