Shi*_*Tio 5 c# asp.net xamarin xamarin.forms
如何克服下面的错误?我已经按照以下教程进行操作,但我得到了不包含Content.
https://www.youtube.com/watch?v=IVvJX4CoLUY
private void UploadFile_Cliked(object sender, EventArgs e)
{
var content = new MultipartFormDataContent();
content.Add(new StreamContent(_mediaFile.GetStream()),
"\"file\"",
$"\"{_mediaFile.Path}\"");
var httpClient = new HttpClient();
var uploadServiceBaseAddress = "http://192.168.137.1/pic/";
var httpResponseMessage = httpClient.PostAsync(uploadServiceBaseAddress, content);
RemotePathLabel.Text = httpResponseMessage.Content.ReadAsStringAsync();
}
Run Code Online (Sandbox Code Playgroud)
“Task”不包含“Content”的定义,并且找不到接受“Task”类型的第一个参数的扩展方法“Content”(您是否缺少 using 指令或程序集引用?)
这是错误,但有解决它的想法吗?
我已经添加了这个Microsoft.AspNet.WebApi.Client包,但仍然失败
使事件处理程序异步,然后等待返回 Task 派生结果的函数,因为您在调用时会遇到相同的问题ReadAsStringAsync
private HttpClient httpClient = new HttpClient();
private async void UploadFile_Cliked(object sender, EventArgs e) {
var content = new MultipartFormDataContent();
content.Add(new StreamContent(_mediaFile.GetStream()),
"\"file\"",
$"\"{_mediaFile.Path}\"");
var uploadServiceBaseAddress = "http://192.168.137.1/pic/";
var httpResponseMessage = await httpClient.PostAsync(uploadServiceBaseAddress, content);
RemotePathLabel.Text = await httpResponseMessage.Content.ReadAsStringAsync();
}
Run Code Online (Sandbox Code Playgroud)
async void请注意,事件处理程序是允许的规则的例外
| 归档时间: |
|
| 查看次数: |
5336 次 |
| 最近记录: |