2013-03-01 107 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);