如何在 RestSharp 中使用 PUT? [英] How do I use PUT in RestSharp?

查看:49
本文介绍了如何在 RestSharp 中使用 PUT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 PUT,但我只能找到如何使用 POST 的示例.我想发送的 json 数据是使用这个 cURL 命令发送的 curl -i -H "Content-Type: application/json" -X PUT -d {"status":1}'http://192.168.0.3:1337/auto/api/v1.0/relays/3 另外我希望状态后的1"和最后的3"是变量.

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.

推荐答案

在创建其余请求时设置方法:

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);
}

(来源)

(航空代码警告)

  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);

(编译小提琴)

这篇关于如何在 RestSharp 中使用 PUT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆