Asp.net web api 如何在xamarin窗体上运行localhost webapi

Asp.net web api 如何在xamarin窗体上运行localhost webapi,asp.net-web-api,xamarin.forms,httpclient,Asp.net Web Api,Xamarin.forms,Httpclient,我有一个xamarin表单应用程序和一个web api 当我运行web api时,在浏览器上 在xamarin应用程序中,我有以下方法 public async Task<object> GetRestfull() { try { using (var client = new HttpClient()) { var content = await client.

我有一个xamarin表单应用程序和一个web api

当我运行web api时,在浏览器上

在xamarin应用程序中,我有以下方法

public async Task<object> GetRestfull()
    {

        try
        {
            using (var client = new HttpClient())
            {
                var content = await client.GetStringAsync("http://10.0.2.2:53089/api/values");
                var postt = JsonConvert.DeserializeObject<List<Post>>(content);
                post = new ObservableCollection<Post>(postt);
            }             

            return post.FirstOrDefault();
        }
        catch (HttpRequestException e)
        {
            Console.WriteLine(e.GetBaseException().Message);
            throw;
        }
    }
public异步任务GetRestfull()
{
尝试
{
使用(var client=new HttpClient())
{
var content=await client.GetStringAsync(“http://10.0.2.2:53089/api/values");
var postt=JsonConvert.DeserializeObject(内容);
post=新的可观测采集(post);
}             
return post.FirstOrDefault();
}
捕获(HttpRequestException e)
{
Console.WriteLine(如GetBaseException().Message);
投掷;
}
}
我正在使用android avd模拟器

上面的代码抛出一个异常:400个错误请求 如果我删除它抛出的端口号:404未找到


我已检查防火墙设置,万维网已启用。。我在这里错过了什么?感谢您的帮助。

尝试将localhost替换为127.0.0.1

我如何将我的restful服务作为网站添加到jexus manager的可能副本?来自评论:您好,这篇文章似乎并没有为这个问题提供答案。请编辑您的答案并加以改进,或者将其作为评论发布。