简体   繁体   中英

WebClient HttpClient Upload From WP8

Seriously i search a lot upload file from WP8 to server. it's doesn't work :(

Why i get this error?? it's the error is because my FileuploadUrl?
System.Net.Http.HttpRequestException: Response status code does not indicate success: 405 (Method Not Allowed)

 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 errors often arise with the POST method. 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.

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.

Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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