我真的很陌生,并且在一般的API请求中,所以不确定我的代码是否有意义。现在我只是想从我的API的URL调用中获取数据,并将其显示在名为testText
的TextView
上。我愿意使用RestSharp
或HttpClient
,无论我可以上班。无法从'字符串'转换为'System.Net.Http.HttpRequestMessage'
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;
}
}
在我的公共async Task<>
方法就是我得到的
无法从 '字符串' 到 'System.Net.Http.HttpRequestMessage'
误差为request
转换变量。我留下了所有其他尝试的意见,让我知道如果我应该尝试其中的任何一种
请去掉所有不需要说明你的问题的注释代码中的同步版本,它只是使你的问题更难阅读 – Jason
完成,抱歉让那些人认为这是一条更好的路线。 –