Reputation: 33
I want to upload files on windows phone but mediafire exception. My code.
public static async Task Upload(byte[] image)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.ExpectContinue = false;
client.DefaultRequestHeaders.Add("Accept", "application/xml");
client.DefaultRequestHeaders.Add("UserAgent", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0");
string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
string hashstr = await Utility.SHA256(image);
// client.DefaultRequestHeaders.Add("x-filehash", hashstr);
//client.DefaultRequestHeaders.Add("x-filesize", image.Length.ToString());
// client.DefaultRequestHeaders.Add("x-filetype", "image/png");
client.DefaultRequestHeaders.TryAddWithoutValidation("x-filehash", hashstr);
client.DefaultRequestHeaders.TryAddWithoutValidation("x-filesize", image.Length.ToString());
client.DefaultRequestHeaders.TryAddWithoutValidation("x-filetype", "image/png");
using (var content = new MultipartFormDataContent(boundary))
{
var file = new ByteArrayContent(image);
content.Add(file, "Logo.scale-100", "Logo.scale-100.png");
string url = String.Format("http://www.mediafire.com/api/upload/upload.php?&uploadkey=&session_token={0}&dropbox=0", Statics.SessionToken);
using (var message = await client.PostAsync(url, content))
{
var input = await message.Content.ReadAsStringAsync();
}
}
}
}
` I'm programming on windows phone 8.1. help me please.
Upvotes: 2
Views: 1884
Reputation: 597
To find what the server response looks like which causes the Protocol Violation error, try recreating the same HTTP request in Fiddler: http://www.telerik.com/fiddler and that should help you understand what the protocol error is all about. Also, this error does not sound Windows Phone Platform specific, and you can probably also reproduce this problem on Windows. If you can then you can collect a System.net trace to understand what the error is all about, steps here: http://blogs.msdn.com/b/jpsanders/archive/2011/12/16/how-to-take-a-system-net-trace-from-metro-style-applications-developer-preview.aspx
Upvotes: 1