小编Fra*_*cia的帖子

无法从“字符串”转换为“System.Net.Http.HttpRequestMessage”

我对 c# 和一般的 API 请求很陌生,所以不确定我的代码是否有意义。现在我只是想从我的 API 的 URL 调用中获取数据并将其显示到一个TextView被调用的testText. 无论我能做什么,我都愿意使用RestSharpHttpClient

public class MainActivity : Activity
{

    HttpClient client;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Main);
    }

    public async Task<string> GetResponseString()
    {
        var request = "http://localhost:51843/api/values/getMessage?id=1";
        var response = await client.SendAsync(request);
        var content = await response.Content.ReadAsStringAsync();
        return content;
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的公共async Task<>方法中,我得到了

无法从“字符串”转换为“System.Net.Http.HttpRequestMessage”

request变量的错误。我留下了所有其他尝试的评论,如果我应该尝试其中任何一个,请告诉我

.net c# asp.net xamarin.android xamarin

1
推荐指数
1
解决办法
8653
查看次数

标签 统计

.net ×1

asp.net ×1

c# ×1

xamarin ×1

xamarin.android ×1