c# - 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();
解决方案
你可以试试这个
string convertedImage = Convert.ToBase64String(data);
HttpContent content = new StringContent(convertedImage, Encoding.UTF8, "application/json");
推荐阅读
- java - 如何存储不合理的 BigDecimal
- java - 将摩尔斯电码转换为英语词典单词
- javascript - 删除 Firestore 中的文档和 Storage 中的文件
- google-api - 当生产中的应用程序意外未经验证时该怎么办?
- javascript - 如果元素被父组件中的 v-if 删除,则在 beforeDestroy 生命周期方法中删除事件侦听器不起作用
- r - 计算由 X、Y 点向量生成的曲线的第 5 个分位数
- amazon-web-services - 如何禁用 S3 存储桶重定向规则?
- javascript - 此页面如何检测桌面浏览器窗口的移动?
- python - 使用@font face 时在 QtWebEngine 中忽略 Google 字体 (ttf)
- python-3.x - HTTPError:服务暂时不可用(维基百科数据转储的多线程下载)