首页 > 解决方案 > Xamarin 表单发送图像

问题描述

我正在尝试使用多部分数据表单将图像发送到我的服务器,但是每当我尝试发送它时,由于缺乏响应而超时。当我尝试发布 HTTPContent 对象时,我能够连接到服务器,但是一旦我抛出 MultiPartFormDataContent 对象就会出现问题。我已经用 html 表单测试了 PHP 代码,所以我知道问题出在我的 Xamarin 代码上

Xamarin 代码:

MultipartFormDataContent Content = new MultipartFormDataContent();
HttpContent FileContent = new ByteArrayContent(Appointment.PicBytes);
Content.Add(FileContent, "AppointmentPicture", "AppointmentPicture");
HttpResponseMessage Response = await Client.PostAsync(Uri, Content);
string Details = await Response.Content.ReadAsStringAsync(); 

标签: c#restxamarinxamarin.formsdotnet-httpclient

解决方案


你可以试试这个

string convertedImage = Convert.ToBase64String(data);
HttpContent content = new StringContent(convertedImage, Encoding.UTF8, "application/json");

推荐阅读