How do I make calls to a REST API using C#?

后端 未结 15 1779
面向向阳花
面向向阳花 2020-11-22 08:10

This is the code I have so far:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Net.Http;
usi         


        
15条回答
  •  独厮守ぢ
    2020-11-22 09:03

    I did it in this simple way, with Web API 2.0. You can remove UseDefaultCredentials. I used it for my own use cases.

    List listObjects = new List();
    
    string response = "";
    using (var client = new WebClient() { UseDefaultCredentials = true })
    {
         response = client.DownloadString(apiUrl);
    }
    
    listObjects = JsonConvert.DeserializeObject>(response);
    return listObjects;
    

提交回复
热议问题