我对 c# 和一般的 API 请求很陌生,所以不确定我的代码是否有意义。现在我只是想从我的 API 的 URL 调用中获取数据并将其显示到一个TextView被调用的testText. 无论我能做什么,我都愿意使用RestSharp或HttpClient。
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变量的错误。我留下了所有其他尝试的评论,如果我应该尝试其中任何一个,请告诉我