题
我正在使用Drupal 6和服务6.3倍模块,但我无法完全使用此模块。我也启用了REST服务器模块。我添加了一项新服务,并为此添加了资源。我在其中添加了节点资源,我能够以JSON格式获取所有节点
我无法理解的是: -
确切的URI或可能是拨打GetTree方法的程序,分类_vocabulary资源
如何在每个资源下启用所有方法(CRUD)功能
url-> mydomain.com/service/rest/node.json为我工作,但是如何访问getTree方法?
我什至在Drupal网站上张贴了工作,但我猜想有一些非常罕见的人对此有所了解。
编辑 :-
实时链接是 http://delvelogic.com/merchant/drupal-6.22/services/rest/taxonomy_vocabulary
以下是我正在使用的Java代码: -
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = null;
HttpPost postMethod = new HttpPost("http://delvelogic.com/merchant/drupal-6.22/rest/taxonomy_vocabulary/getTree.json");
postMethod.addHeader("Content-type", "application/x-www-form-urlencoded");
postMethod.addHeader("Accept","application/json");
// postMethod.addHeader("Authorization", "basic " + Base64.encodeBytes(("admin"+":"+"admin123").getBytes()));
// httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT));
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("vid", ""+1));
nameValuePairs.add(new BasicNameValuePair("parent", ""+1));
nameValuePairs.add(new BasicNameValuePair("maxdepth",""+1));
// nameValuePairs.add(new BasicNameValuePair())
try{
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpClient.execute(postMethod);
InputStream input = response.getEntity().getContent();
BufferedReader rd = new BufferedReader(new InputStreamReader(input),input.toString().length());
String line;
StringBuilder sb = new StringBuilder();
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
uploadresponse = sb.toString();
Log.d("Response", ""+uploadresponse);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
另外,如果有任何firefox添加,以便我实际上可以看到该方法的工作方式?
再次编辑: -
我发现这增加了RESTCLIENT,可以在Firefox上工作
我选择该方法作为我输入的URL中的帖子 http://delvelogic.com/merchant/drupal-6.22/services/rest/taxonomy_vocabulary/gettree
添加了标头: -
内容类型:应用程序/x-www-form-urlenCoded
接受:应用程序/JSON
请求主体: -
&vid = 1&parent = 1&maxDepth = 1
它给了我404,没有发现没有词汇,没有ID 1的词汇。
解决方案
根据文档,URL不一定在最后具有.json,但是我想这是一个为节点函数工作的设置。我知道您不会喜欢这个答案(我很确定您以前尝试过),但是URL是: mydomain.com/service/rest/taxonomy_vocabulary/getTree
. 。我什至经历了服务和REST_SERVER模块的各自代码,这绝对是应该的。
为了进一步证明,请查看服务分类法的(有效,通过的)测试模块:vocabulary:
ServicesResourcetaxonomyTests :: TestVocabularygetTree.
您会发现该成功传递的测试访问的URL是: $path . '/taxonomy_vocabulary/getTree'
, , 在哪里 $path
是通往终点的路径(即 mymodule.com/service/rest/
).
如果您可以提供一个实时链接,这确实会有所帮助,因此我们可以测试以查看问题是在您的Java代码中还是使用Drupal(尽管后者似乎不太可能)。
编辑
PS对此答案进行评论,因为我在服务模块上有很多经验,而且我敢肯定,我可以用更多信息指向您的正确方向。看到有人在过去的事情上挣扎着,我很难过!
另一个编辑
这是我从中得到的回应 http://delvelogic.com/merchant/drupal-6.22/services/rest/taxonomy_vocabulary
:
<?xml version="1.0" encoding="utf-8"?>
<result>
<nodes/>
<module>taxonomy</module>
<name></name>
<help></help>
<relations>0</relations>
<hierarchy>0</hierarchy>
<multiple>0</multiple>
<required>0</required>
<tags>0</tags>
<weight>0</weight>
<vid>4</vid>
</result>
注意 <vid>4</vid>
一点...我很确定 vid
你应该寻找的是 4
, , 不是 1
!