Reputation: 317
Hello I'm just searching for more than 2 days... My problem: I want to send a Post Request to a Server and send a File (FileBody) with this post.
I've found many examples for this with the WebClient class. But I am a newbee to C# and Windows Phone development and so i did not get it to work. Because the only method i see is "UploadStringAsync" but the method mentioned everywhere in the internet "UploadFile" is not available in my object.
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);
The problem is i have to send a FileBody as mentioned here: http://www.codescales.com/category/howto/
But i cant reference this project to my windows phone project. I am very confused right now and hope anyone can help me with this.
Upvotes: 0
Views: 403
Reputation: 5773
You can use RestSharp, (Nuget it)
Contains several options to upload files:
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);
Upvotes: 1