首页 新闻 搜索 专区 学院

使用asp.ne web api 上传图片问题

0
[待解决问题]

现在使用asp.net web api2.0从IOS上传图片,问题是我还想传一些用户信息比喻说用户ID

Result UploadHeadImage([FromBody] LoginUserModel model)

{

   

}

 public class LoginUserModel
    {
        public int UserId { get; set; }
        public string TokenId { get; set; }
    }

 

IOS端怎样设置才能付值LoginUserModel,或者.net客户端怎能设置,下面是我的例子

HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("http://localhost/Fitness.WebUI/");
            client.DefaultRequestHeaders.Add("qhapi", "xiong");
            #region

            LoginUserModel model=new LoginUserModel();
            model.UserId = 1;
            model.TokenId = "dfdfdfd";
            MediaTypeFormatter jsonFormatter = new JsonMediaTypeFormatter();
            HttpContent content = new ObjectContent<LoginUserModel>(model, jsonFormatter);

            MultipartFormDataContent form = new MultipartFormDataContent();
            form.Add(new StringContent("1"), "UserId");
           // form.Add(new StringContent("asasasasasa"), "TokenId");

            StreamContent fileContent = new StreamContent(File.OpenRead(@"J:\3_03c1bf119bba2642232978cfead8e239_212.jpg"));
            fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
            fileContent.Headers.ContentDisposition.FileName = "3_03c1bf119bba2642232978cfead8e239_212.jpg";
            form.Add(fileContent);
            #endregion

            HttpResponseMessage res = client.PostAsync("api/v1/User/UploadHeadImage", form).Result;
            var uploadModel = res.Content.ReadAsStringAsync().Result;

请问那里有问题,谢谢

 

 

 

 

冷火的主页 冷火 | 初学一级 | 园豆:4
提问于:2015-03-10 16:27
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册