上传图像和数据的多部分内容 - 的Windows Phone 8 [英] Uploading image and data as multi part content - windows phone 8

查看:277
本文介绍了上传图像和数据的多部分内容 - 的Windows Phone 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法上传图片和数据,以Web服务为多部分content.Here是我的code

I am unable to upload image and data to web service as multipart content.Here is my code

 var fileUploadUrl = @"http://myurl";
                    var client = new HttpClient();
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "multipart/form-data");
                    photoStream.Position = 0;

                    // This is the postdata
                    MultipartFormDataContent content = new MultipartFormDataContent();
                    content.Add(new StreamContent(photoStream), "attendeedImage");
                    content.Add(new StringContent("12", Encoding.UTF8), "userId");
                    content.Add(new StringContent("78", Encoding.UTF8), "noOfAttendees");
                    content.Add(new StringContent("chennai", Encoding.UTF8), "locationName");
                    content.Add(new StringContent("32.56", Encoding.UTF8), "longitude");
                    content.Add(new StringContent("32.56", Encoding.UTF8), "latitude");

                    Console.Write(content);
                    // upload the file sending the form info and ensure a result.
                    // it will throw an exception if the service doesn't return a valid successful status code
                    await client.PostAsync(fileUploadUrl, content)
                        .ContinueWith((postTask) =>
                        {
                            postTask.Result.EnsureSuccessStatusCode();
                        });

我得到的回应是400-错误请求

The response I get is 400- Bad request

时,可将这两种图像和数据一起发送这样吗? 如果是,什么是正确的方式去?

Is is possible to send both image and data together like this? If yes, what is the proper way to go about?

推荐答案

我现在还不能测试这一权利,但问题可能是你的数据项之间缺少边界。要指定一个,initializting你的 MultipartFormDataContent 如下:

I can't test this right now, but the problem could be a missing boundary between your data items. To specify one, initializting your MultipartFormDataContent as follows:

string boundary = "---###---"; // should never occur in your data
MultipartFormDataContent content = new MultipartFormDataContent(boundary);

更多关于边界:什么是多部分的边界/形式 - 数据?

这篇关于上传图像和数据的多部分内容 - 的Windows Phone 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆