【问题标题】:Xamarin Forms Sending ImageXamarin 表单发送图像
【发布时间】:2020-08-06 18:36:25
【问题描述】:

我正在尝试使用多部分数据表单将图像发送到我的服务器,但每当我尝试发送它时,由于缺乏响应而超时。当我尝试发布 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# rest xamarin xamarin.forms dotnet-httpclient


【解决方案1】:

你可以试试这个

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

【讨论】:

    猜你喜欢
    • 2018-07-08
    • 1970-01-01
    • 2018-07-11
    • 2020-06-10
    • 2021-01-08
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    • 2016-11-01
    相关资源
    最近更新 更多