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

后端 未结 15 1773
面向向阳花
面向向阳花 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 08:52

    Calling a REST API when using .NET 4.5 or .NET Core

    I would suggest DalSoft.RestClient (caveat: I created it). The reason being, because it uses dynamic typing, you can wrap everything up in one fluent call including serialization/de-serialization. Below is a working PUT example:

    dynamic client = new RestClient("http://jsonplaceholder.typicode.com");
    
    var post = new Post { title = "foo", body = "bar", userId = 10 };
    
    var result = await client.Posts(1).Put(post);
    

提交回复
热议问题