我正在使用C#来使用Drupal的Rest Api。我正在使用drupal 7.5,并在各种资源之后使用它的rest services/api。用c来消费Drupal的RestApi#
我已经成功与谷歌的邮递员张贴的内容,但当我尝试复制它与C#代码我被提示禁止错误说:访问被拒绝用户匿名。 我正在利用rest-sharp来使用此API。我研究了很多,还没有找到解决方案,以及没有发现任何人在c#中做这项工作。 以下是代码片段,我基于邮递员
var client = new RestClient("drupasitename/rest/node");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("authorization", authorisation);
request.AddHeader("x-csrf-token", token);
request.AddHeader("cookie", cookie);
request.AddHeader("content-type", "application/json");
request.AddHeader("Accept", "application/json");
request.AddParameter("application/json", "{\r\n \"type\":\"page\",\r\n \"title\":\"Page submitted via JSON REST\",\r\n \"body\":{\r\n \"und\":[\r\n {\r\n \"value\":\"This is the body of the page.\"\r\n }\r\n ]\r\n }\r\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
饼干书面和令牌使用C#代码成功登录尝试后获得的。
如果有人能够提供解决这个问题的指导,那将是非常好的。 问候
这是否帮助? http://drupal.stackexchange.com/questions/97993/rest-services-module-access-denied-for-user-anonymous –
我跟着链接之前,我已成功地让它在邮递员完成,但是当我写代码并尝试使用它,“拒绝匿名用户访问”的错误仍然存在 – shunilkarki
您是否尝试将UserAgent添加到请求标头中? –