2009-11-13 56 views
0

我有一個桌面應用程序在我的桌面上運行。 我需要將文件路徑發送到在服務器上運行的CGI腳本。 CGI腳本獲取文件路徑並從我的機器上傳內容。幫助需要在Windows Mobile上傳文件

我試圖通過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的不implimented ...... 請告訴如何在移動

+1

定義「不工作」;怎麼了? *究竟*。你有沒有試過網絡追蹤? – 2009-11-13 07:11:08

+0

請注意,在第二個例子中,你還沒有真正上傳任何東西......第一個例子看起來很有前途(不知道你爲什麼寫了這樣的路徑 - 他們看起來很奇怪)。在您澄清症狀之前,我們無法診斷。 – 2009-11-13 07:12:58

+0

你還需要澄清一下cgi期待的是什麼?它是否期待請求正文中的單個文件?還是期待多部分表單編碼? – 2009-11-13 07:13:55

回答

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

Yup marc,你的代碼工作.. 我做的小改動是,我沒有設置任何憑據服務器.. – Naruto 2009-11-13 09:31:02

+1

馬克我同意你..我有一個更多的概率.. WebClient不支持在Windows Mobile ... 我怎麼能在Windows Mobile中實現相同的操作 – Naruto 2009-11-13 11:09:09