C# 如何在xamarin.android中使用HttpClient将数据传递到服务器

C# 如何在xamarin.android中使用HttpClient将数据传递到服务器,c#,post,xamarin.android,dotnet-httpclient,C#,Post,Xamarin.android,Dotnet Httpclient,我正在xamarin开发一个android应用程序,现在我想发出post请求并将以下数据发送到服务器 Name EmailID Prod_EMAILID ID 并从服务器获得响应。我做过类似的事情 static async Task CallWebAPIAsync() { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:55587/")

我正在xamarin开发一个android应用程序,现在我想发出post请求并将以下数据发送到服务器

Name 
EmailID
Prod_EMAILID
ID
并从服务器获得响应。我做过类似的事情

static async Task CallWebAPIAsync()
{
    using (var client = new HttpClient())
    {
        client.BaseAddress = new Uri("http://localhost:55587/");
        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));                

        //POST Method
        var post = new Post() { Id = 1,NAME="aaaaa222",PROF_EMAILD="aaa@gmail.com",MAILID="asasa@gmail.com" };
        HttpResponseMessage responsePost = await client.PostAsJsonAsync("api/Department", post);
        if (responsePost.IsSuccessStatusCode)
        {
            // Get the URI of the created resource.
            Uri returnUrl = responsePost.Headers.Location;
            Console.WriteLine(returnUrl);
        }        
    }
    Console.Read();    
}

但它只适用于GET方法,现在我想发出post请求,在Httpclient中,以下是我在解决方案中使用Httpclient的方法

using (var client = new HttpClient())
{
    var content = new StringContent(JsonConvert.SerializeObject(myPoco));
    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

    var response = await client.PostAsync(new Uri("http://your-url"), content);

    /* handle response here*/
};

如果myPoco是您的普通C#objet

我建议您研究一下它,它可以连接到您的API并将JSON结果解析为C#objet。我想使用HttpClient。如何实现它您遇到了什么错误?HttpClient不包含PostsJSonAsynchnow的定义现在我得到了一个错误,就像当前代码中不存在Encoding这个名称一样上下文