gpt4 book ai didi

c# - 使用 Raspberry pi 调用 rest API windows 10 IoT

转载 作者:太空狗 更新时间:2023-10-30 01:17:51 24 4
gpt4 key购买 nike

我正在尝试使用适用于 Windows 10 IoT 的通用应用程序来做一些像调用 REST API 这样简单的事情,但我找不到实现它的方法。

通常我会使用:

private XElement ImportData(string sourceUrl)
{

WebClient wc = new WebClient();

String source = wc.DownloadString(sourceUrl);
return XElement.Parse(source, LoadOptions.None);

}

但它不可用。

最佳答案

您应该使用 HttpClient 而不是 WebClient。试试这个

HttpClient client = new HttpClient();
string url = "URL here";
HttpResponseMessage response = await client.GetAsync(url);
return response.Content.ReadAsString();

关于c# - 使用 Raspberry pi 调用 rest API windows 10 IoT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30179581/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com