当前位置: 首页 > 工具软件 > easyhttp > 使用案例 >

c# EasyHttp的使用(一)

惠野
2023-12-01

github资源下载地址:

https://github.com/EasyHttp/EasyHttp.git

实现了简单的http客户端库。

VS可以通过NuGet方式下载库文件。

post Json数据举例子:

   public class Customer
    {
        public string Name;
        public string Email;
    }

    class Program
    {
        static void Main(string[] args)
        {
            var customer = new Customer();
            customer.Name = "Joe";
            customer.Email = "joe@smith.com";
            EasyHttp.Http.HttpClient htpclient = new EasyHttp.Http.HttpClient();
            htpclient.Post("http://localhost:8080/", customer, EasyHttp.Http.HttpContentTypes.ApplicationJson);
        }
    }

服务端就会收到如下的Json格式数据:

Content-Type: application/json
Accept: text/html;application/xml;application/json
User-Agent: EasyHttp HttpClient v1.7.0.0
Host: localhost:8080
Content-Length: 38
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

{"Name":"Joe","Email":"joe@smith.com"}

 

 类似资料: