Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# v2中的Woocommerce REST API POST不工作_C#_Api_Rest_Woocommerce_Restsharp - Fatal编程技术网

C# v2中的Woocommerce REST API POST不工作

C# v2中的Woocommerce REST API POST不工作,c#,api,rest,woocommerce,restsharp,C#,Api,Rest,Woocommerce,Restsharp,我已升级到V2,在从C#(使用RestSharp)将更新发布到我的Windows服务器上时遇到问题 GET在V1和V2中都能工作 更改订单状态(订单81)在V1中工作,使用以下代码: var client = new RestClient("https://mysite.com"); client.Authenticator = new HttpBasicAuthenticator("ck_6c5bbb4e467d1994d2428a476bxxxxxx",

我已升级到V2,在从C#(使用RestSharp)将更新发布到我的Windows服务器上时遇到问题

GET在V1和V2中都能工作

更改订单状态(订单81)在V1中工作,使用以下代码:

var client = new RestClient("https://mysite.com");
client.Authenticator = new HttpBasicAuthenticator("ck_6c5bbb4e467d1994d2428a476bxxxxxx",
                                              "cs_008adefb1692a708e9795de9fxxxxxx");
var requestv1 = new RestRequest("wc-api/v1/orders/{id}", Method.POST);
requestv1.RequestFormat = DataFormat.Json;
requestv1.AddBody(new { status = "completed" }); 
requestv1.AddParameter("id", 81, ParameterType.UrlSegment);
var queryResultv1 = client.Execute<WC_Manager.OrderSingle>(requestv1);
var client=new RestClient(“https://mysite.com");
client.Authenticator=新的HttpBasicAuthenticator(“ck_6c5bbb4e467d1994d2428a476bxxxxxx”,
“cs_008adefb1692a708e9795de9fxxxxxx”);
var requestv1=new RestRequest(“wc-api/v1/orders/{id}”,Method.POST);
requestv1.RequestFormat=DataFormat.Json;
requestv1.AddBody(新的{status=“completed”});
requestv1.AddParameter(“id”,81,ParameterType.UrlSegment);
var queryResultv1=client.Execute(requestv1);
将资源更改为“wc api/v2/orders/{id}”不会产生任何错误,Execute现在仍然返回订单以及v2中的额外字段,但是queryresult或数据库中的状态没有更改。
尝试在V2中发布产品更新时出现相同问题


尝试放置或删除会给我一个“不允许使用的方法”。

您可以使用以下内容添加正文内容:

string bodyContent;
bodyContent = "{ \"status\": \"completed\" , ";
bodyContent += "\"customer_note\": \"" + customerNote + "\" }";    
request.AddParameter("application/json", bodyContent, ParameterType.RequestBody);

我意识到V2在JSON中有一个额外的级别,名为“order”。所以我需要向主体添加一个对象,而不仅仅是一个参数。