将参数传递给RestSharp GET请求

降低者

我正在尝试与Drupal站点进行通信以访问特定节点。我正在使用C#和RestSharp来访问数据。我可以在FireFox RestClient中使用以下工具:

http:// localhost / drupal / gpa / node?parameters [type] = product_activation

它返回正确的节点类型。但是,我尝试使用RestSharp编写的代码都无法正常工作。我要么得到所有节点类型,要么根本不得到。我使用的代码:

restClient = new RestClient(“http://localhost/drupal/gpa/node”);
RestRequest request = new RestRequest();

request.Method = Method.GET;
request.AddHeader("Content-Type", "application/json");
request.AddHeader("X-CSRF-Token", csrftoken);
request.AddHeader("Cookie", sessid);
request.AddParameter("type", "product_activation", ParameterType.GetOrPost);

var response = restClient.Execute(request);

这导致返回每个节点。并且,响应uri是:

{ http:// localhost / drupal / gpa / node?type = product_activation }

谁能解释如何更正参数的传递以仅访问所请求的类型?

降低者

我能够解决这个问题。通过一些调试编码,我注意到即使拉出所有节点,我正在寻找的类型也丢失了。这使我指向了Drupal系统,在那里我发现该节点未“发布”。这意味着对于外部世界,该节点不存在。因此,我无法检索它。一旦使节点“发布”,此代码便起作用:

restClient = new RestClient(RestGetNodes);
RestRequest request = new RestRequest();

request.Method = Method.GET;
request.AddHeader("Content-Type", "application/json");
request.AddHeader("X-CSRF-Token", csrftoken);
request.AddHeader("Cookie", sessid);
request.AddParameter("parameters[type]", "product_activation");

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章