我是C#的新手,并尝试在API发出http请求后更新标签文本,但没有成功。 我是这样做的:
Auth::attempt()
我可以在控制台中看到正确的文字,但标签只显示"您的API密钥:"
即使在尝试使用BackgroundWorker后,我也没有成功。我做错了吗?
答案 0 :(得分:0)
将您的代码更改为以下内容,看看是否有帮助。
private async string getApiKey()
{
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("http://localhost:61128/StationService.svc/");
HttpResponseMessage response = await httpClient.GetAsync("key");
if(response==null)
{
// something went wrong
}
var ApiKeyString = await response.Content.ReadAsStringAsync();
var ApiKey = JsonConvert.DeserializeObject<string>(ApiKeyString);
return ApiKey;
}