2013-03-01 117 views
0

你好,我只是尋找超過2天... 我的問題:我想發送一個發佈請求到服務器,併發送文件(FileBody)與這篇文章。Windows Phone 8發送文件HttpClient FileBody

我發現很多WebClient類的例子。但我是C#和Windows Phone開發的新手,所以我沒有得到它的工作。因爲我看到的唯一方法是「UploadStringAsync」,但在互聯網「UploadFile」中隨處可見的方法在我的對象中不可用。

string postdata = string.Format("cmd={0}&", "show"); 
postdata += string.Format("latitude={0}&", HttpUtility.UrlEncode("-1")); 
... 

WebClient wc = new WebClient(); 
wc.UploadStringAsync(new Uri("http://mydomain/myphp.php", UriKind.Absolute), "POST", postdata); 

的問題是我有送FileBody這裏提到:http://www.codescales.com/category/howto/

,但我不能引用這個項目到我的Windows Phone項目。 我現在很困惑,希望任何人都可以幫助我。

回答

1

您可以使用RestSharp,(它的NuGet)

包含幾個選項來上傳文件:

public IRestRequest AddFile(string name, string path); 
    public IRestRequest AddFile(string name, Action<System.IO.Stream> writer, string fileName); 
    public IRestRequest AddFile(string name, byte[] bytes, string fileName);  
    public IRestRequest AddFile(string name, Action<System.IO.Stream> writer, string fileName, string contentType);  
    public IRestRequest AddFile(string name, byte[] bytes, string fileName, string contentType);