How do I use PUT in RestSharp?

夙愿已清 提交于 2019-12-22 06:37:11

问题


I want to use PUT, but I can only find examples of how to use POST. The json data I want to send is sent using this cURL command curl -i -H "Content-Type: application/json" -X PUT -d {"status":1}'http://192.168.0.3:1337/auto/api/v1.0/relays/3 Also I want the "1" after status and the last "3" to be variables.


回答1:


Set the method as you create the rest request:

public void Update(int id, Product product)
{
  var request = new RestRequest("Products/" + id, Method.PUT);
  request.AddJsonBody(product);
  client.Execute(request);
}

(Source)


(Aircode Warning)

  var status = 1;
  var id = 3;
  var request = new RestRequest("/auto/api/v1.0/relays/" + id, Method.PUT);
  request.AddJsonBody(new { status = status });
  client.Execute(request);

(Compiling Fiddle)



来源:https://stackoverflow.com/questions/35246586/how-do-i-use-put-in-restsharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!