2015-04-12 67 views
0

我希望我的客戶端軟件使用http將文件發送到我的Linux服務器。這是我行C# - 使用http發送文件到Linux目錄

WebClient client = new WebClient(); client.UploadFile("http://192.168.121.128/musiclocation/", file);

其中「文件」是我上傳的文件的路徑。當我運行我的代碼我收到錯誤

An unhandled exception of type 'System.Net.WebException' occurred in System.dll

Additional information: The remote server returned an error: (404) Not Found.

我知道我的軟件可以找到服務器,因爲我在客戶端工作完全正常其他地方的代碼(它不會拋出異常)。

MusicPlayer.PlayMp3FromUrl("http://192.168.121.128/musiclocation/" + dataGridView1.Rows[rownumber].Cells["path"].Value.ToString()); 

我的apache設置是默認的,除了/ musiclocation /這是我的home文件夾中的目錄的別名。

Alias /musiclocation/ /home/homefolder/MusicStorage/ 
<Directory /home/homefolder/MusicStorage/> 
options +Indexes 
order allow,deny 
Allow from all 
</Directory> 

是否需要進一步配置apache以允許通過WebClient上傳。或者我誤解了WebClient上傳如何工作?我最困惑的是爲什麼我得到一個404錯誤。因爲我知道我的服務器可以訪問,所以我希望至少有403錯誤。

任何意見或建議,以幫助我解決這個問題將不勝感激。

回答

0

UploadFile方法只能將數據發送到服務器上的資源,它不能將數據保存爲服務器上的文件。

您正在將數據發送到服務器上的文件夾名稱,但服務器上沒有該名稱可以接收數據的資源。您需要服務器上的一個頁面,該頁面可以獲取請求中發送的數據並將其作爲文件保存在服務器上。