异常服务器提交了协议违规。第= ResponseStatusLine

时间:2015-04-14 05:46:33

标签: c# windows-phone-8.1 win-universal-app

我想在Windows手机上传文件但是媒体火灾例外。我的代码。

 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();

                }
            }
        }
    }

` 我在Windows Phone 8.1上编程。请帮帮我。

1 个答案:

答案 0 :(得分:1)

要查找导致协议违规错误的服务器响应,请尝试在Fiddler:http://www.telerik.com/fiddler中重新创建相同的HTTP请求,这样可以帮助您了解协议错误的全部内容。此外,此错误不会特定于Windows Phone平台,您也可能在Windows上重现此问题。如果可以,那么您可以收集System.net跟踪以了解错误的全部内容,请执行以下步骤:http://blogs.msdn.com/b/jpsanders/archive/2011/12/16/how-to-take-a-system-net-trace-from-metro-style-applications-developer-preview.aspx