如何使用Xamarin Form将Stream形式的图像上传到多部分休息服务

时间:2015-12-31 09:07:53

标签: c# xamarin xamarin.ios xamarin.forms xamarin-forms

我使用的是此代码,但发现xamarin中的System.Net没有 GetRequestStreamAsync GetResponseAsync 的定义。

那么将文件上传到服务器的替代方法是什么呢?

struct sockaddr_in6 client6;
memset(&client6, 0, sizeof(client6));
client6.sin6_family = AF_INET6;
client6.sin6_port = htons(5000);
memcpy(&client6.sin6_addr, server->h_addr_list[0], server->h_length);

1 个答案:

答案 0 :(得分:1)

ABHI。

您可以使用System.Net.Http中的HttpClient(我记得需要安装NuGet包)。简单的方法看起来像这样:

HttpClient client = new HttpClient();
ByteArrayContent content = new ByteArrayContent(yourBytesHere);
HttpResponseMessage response = await client.PostAsync(urlHere, content);

此外,如果您不仅需要发送文件,还需要发送其他一些数据,请使用MultipartFormDataContent;

相关问题