消费方法的参数api c# put 2(String, Object)

Consume the parameters of the method api c # put 2 (String, Object)

我正在尝试使用这种类型的 api:

 api / food_order / {id}

这个想法来自一个控制台项目。

我找到了这段代码:

client.BaseAddress = new Uri ("http: // localhost: 1565 /");
var response = client.PutAsJsonAsync ("api / food_order", p) .Result;

细节是它发送对象p但想法是发送对象p 除了字符串 {id}

因为您提到您正在尝试使用 api : api/food_order/{id}

尝试更改为:

var response = client.PutAsJsonAsync($"api/food_order/{id}", p) .Result;

of 如果您尝试将 id 作为正文的一部分传递,请尝试更改为:

var response = client.PutAsJsonAsync("api/food_order", new { Id = id, P = p }).Result;