首页 > 其他分享 >RestSharp 最简代码

RestSharp 最简代码

时间:2024-08-19 14:05:18浏览次数:11  
标签:最简 thread Thread 代码 request 语音 var new RestSharp

安装的版本

NuGet\Install-Package RestSharp -Version 106.12.0

 

代码如下

internal class Program
{
     static void Main(string[] args)
     {

        语音实体 x = new 语音实体();
         x.text = "重量" + 32 + "公斤,请下磅";
         Thread thread = new Thread(() => 发送语音(x));
         thread.Start();
         Console.ReadKey();
     }

    private static void 发送语音(语音实体 x)
     {
         var client = new RestClient("http://10.30.25.234/v1/speech");
         var request = new RestRequest(Method.POST);
         request.AddHeader("Content-Type", "application/json");
         request.AddJsonBody(x);
         var response = client.Execute<dynamic>(request);
         Console.WriteLine(response.Content);
     }

 

image

 

 

多线程中调用此方法

Thread thread = new Thread(() => 发送语音(x));
thread.Start();

 

标签:最简,thread,Thread,代码,request,语音,var,new,RestSharp
From: https://www.cnblogs.com/hlm750908/p/18367193

相关文章