简体   繁体   English

从WP8上传WebClient HttpClient

[英]WebClient HttpClient Upload From WP8

Seriously i search a lot upload file from WP8 to server. 认真地,我搜索了很多从WP8上传到服务器的文件。 it's doesn't work :( 这是行不通的:(

Why i get this error?? 为什么我会收到此错误?? it's the error is because my FileuploadUrl? 这是因为我的FileuploadUrl吗?
System.Net.Http.HttpRequestException: Response status code does not indicate success: 405 (Method Not Allowed) System.Net.Http.HttpRequestException:响应状态代码未指示成功:405(不允许使用方法)

 private async void UploadFile()
    {
        try
        {
            if (photoStream != null)
            {
                 //var fileUploadUrl = @"http://<IPaddress>:<port>/fileupload";
                var fileUploadUrl = @"http://www.comevox.com:80/services";
                var client = new HttpClient();
                photoStream.Position = 0;

                MultipartFormDataContent content = new MultipartFormDataContent();
                content.Add(new StreamContent(photoStream), "file", fileName);

                await client.PostAsync(fileUploadUrl, content)
                    .ContinueWith((postTask) =>
                    {
                        postTask.Result.EnsureSuccessStatusCode();
                    });
            }

            btnUpload.IsEnabled = false;
            imgSelectedImage.Source = null;
            txtMessage.Visibility = Visibility.Visible;
        }
        catch
        {
            txtError.Visibility = Visibility.Visible;
        }
    }
}

Fixing 405 errors - general 修复405错误-常规

405 errors often arise with the POST method. POST方法通常会出现405错误。 You may be trying to introduce some kind of input form on the Web site, but not all ISPs allow the POST method necessary to process the form. 您可能正在尝试在Web站点上引入某种输入形式,但是并非所有ISP都允许处理该形式所必需的POST方法。

All 405 errors can be traced to configuration of the Web server and security governing access to the content of the Web site, so should easily be explained by your ISP. 可以将所有405错误归结为Web服务器的配置和控制对网站内容的访问的安全性,因此,您的ISP应该很容易地对其进行解释。

Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM