使用HttpWebRequest类:
```C#
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://example.com/api/data")
request.Method = "GET"
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string json = reader.ReadToEnd()
// Do something with the json
}
}
```
2. 使用WebClient类:
```C#
using (WebClient wc = new WebClient())
{
string json = wc.DownloadString("http://example.com/api/data")
// Do something with the json
}
```
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)