drupal 和 appcelerator titan 之间的 node.save 服务存在问题
我正在使用 Appcelerator Titanium 编写我的第一个应用程序,但我遇到了一个似乎可以摆脱的障碍。我使用过的所有其他服务都是通过 JSON 服务器(node.get、view.get、system.connect)工作的,但我一生都无法获得 node.save 的工作解决方案。我尝试过寻找与我同一条船上的人,但找不到任何东西,但我也无法在任何地方找到可行的解决方案。
我使用以下博客文章作为起点: http://civicactions.com/blog/2010/may/02/tutorial_code_developing_apps_iphoneipadandroid_using_drupal_base_system
我尝试过 JSON 和 XMLRPC,但 JSON 没有任何响应,并且 XMLRPC 拒绝访问。如果我通过 drupal admin 将 JSON 插入服务页面,它将创建一个节点(不是 CCK 节点,但它与故事一起使用),但浏览应用程序时我什么也得不到。
以下是我尝试使用 XMLRPC 的输出:
节点对象 -
[INFO] {
sessid = b03429453c85d4bf3d600dff6511f70f;
title = "This is a new node.";
type = story;
}
[INFO] xmlrpc: begin
[INFO] xmlrpc: url: http://mysite/services/xmlrpc
[INFO] xmlrpc: method: node.save
[INFO] xmlrpc: p: story
[INFO] xmlrpc: p: This is a new node.
[INFO] xmlrpc: p: b03429453c85d4bf3d600dff6511f70f
正在发送 XML -
[INFO] xmlrpc: xml: <methodCall><methodName>node.save</methodName><params><param><string>story</string></param><param><string>This is a new node.</string></param><param><string>b03429453c85d4bf3d600dff6511f70f</string></param></params></methodCall>
[INFO] xmlrpc: end
响应 -
[INFO] Received: <?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>401</int></value>
</member>
<member>
<name>faultString</name>
<value><string>Access denied</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>
这是我使用 JSON 得到的结果:
[INFO] {"method":"node.save","type":"story","title":"This is a new node.","sessid":"b03429453c85d4bf3d600dff6511f70f"}
[INFO] node.save response: undefined
[WARN] Exception in event callback. {
line = 90;
message = "Unable to parse JSON string";
name = SyntaxError;
sourceId = 204738256;
sourceURL = "file://localhost/Users/justin/Sites/Apps/appname/Resources/add.js";
}
我没有拒绝访问,但它没有将响应发送回应用程序。
有其他人遇到过这个问题吗?如果是的话,您能找到解决办法吗?
I am writing my first app using Appcelerator Titanium and I've hit a snag that I can seem to shake. Every other service I have used is working through the JSON server (node.get, view.get,system.connect) but I cannot for the life of me get a working solution of node.save. I've tried searching for people in my same boat and can't really find anything but I also cannot find a working solution anywhere.
I used the following blog post as a starting point:
http://civicactions.com/blog/2010/may/02/tutorial_code_developing_apps_iphoneipadandroid_using_drupal_base_system
I've tried both JSON and XMLRPC but I get no response with JSON and Access Denied with XMLRPC. If I plug my JSON into the services page through drupal admin it will create a node (not a CCK node but it worked with story) but going through the app I get nothing.
The following is my output trying with XMLRPC:
Node object -
[INFO] {
sessid = b03429453c85d4bf3d600dff6511f70f;
title = "This is a new node.";
type = story;
}
[INFO] xmlrpc: begin
[INFO] xmlrpc: url: http://mysite/services/xmlrpc
[INFO] xmlrpc: method: node.save
[INFO] xmlrpc: p: story
[INFO] xmlrpc: p: This is a new node.
[INFO] xmlrpc: p: b03429453c85d4bf3d600dff6511f70f
XML being sent -
[INFO] xmlrpc: xml: <methodCall><methodName>node.save</methodName><params><param><string>story</string></param><param><string>This is a new node.</string></param><param><string>b03429453c85d4bf3d600dff6511f70f</string></param></params></methodCall>
[INFO] xmlrpc: end
Response -
[INFO] Received: <?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>401</int></value>
</member>
<member>
<name>faultString</name>
<value><string>Access denied</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>
Here is what I am getting with JSON:
[INFO] {"method":"node.save","type":"story","title":"This is a new node.","sessid":"b03429453c85d4bf3d600dff6511f70f"}
[INFO] node.save response: undefined
[WARN] Exception in event callback. {
line = 90;
message = "Unable to parse JSON string";
name = SyntaxError;
sourceId = 204738256;
sourceURL = "file://localhost/Users/justin/Sites/Apps/appname/Resources/add.js";
}
I'm not getting access denied but it isn't sending a response back to the app.
Has anyone else ran into this issue and if so have you been able to find a fix for it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
目前 Sumit 博客中修改后的 JSON 服务器存在一些问题。该补丁是为了与以前版本的 services 2 一起使用而制作的。两天前我正在处理同样的问题。我非常疯狂地工作,不幸的是我不再记得一切是如何展开的。问题之一是过时的 json 服务器模块导致服务崩溃。同样,我不再记得细节,但这是我找到的解决方案。它仅适用于 php 5.2 +,因为它使用 json_encode 和 json_decode。首先拉取最新稳定版本的 JSON Server。
要点是 json_decode 应该返回关联数组而不是 php 对象,因为这是 Drupal 所期望的。所以你调用 json_decode($json_string,TRUE),使用布尔开关使 json_decode 返回 assoc 数组。下面是一个快速但非常肮脏的解决方案:
There are a few problems with the modified JSON server from Sumit's blog at this moment. The patch was made to work with a previous version of services 2. Two days ago I was dealing with the same issue. I was working quite frantically and unfortunaly don't remember anymore how everything unfolded. One of the issues is that the outdated json server module makes services crash. Again, I don't remember the details anymore, but here is the solution I found. It's php 5.2 + only , as it uses json_encode and json_decode. First pull the latest stable version of JSON Server.
Main point is that json_decode should return associative arrays instead of php objects, as that is what Drupal is expecting. So you call json_decode($json_string,TRUE), using the boolean switch makes json_decode return assoc arrays. So below a quick and very dirty solution:
尝试将参数放在引号之间;像“节点.保存”;它对我有用。
Try wrapping your parameters between quotes; like "node.save"; it worked for me.
node.get
、view.get
和system.connect
使用与node.save
不同的权限。它们很可能都被授权给匿名用户,而node.save
则没有。既然您提到了system.connect,我猜您已经尝试在调用node.save之前启动经过身份验证的会话。您确定通话之间的会话得到正确维护吗?此外,
这看起来更像是处理服务器响应的应用程序代码中的异常,而不是服务器端的错误。这很可能是由于服务器在拒绝访问时返回 HTTP 403 错误而没有 JSON 正文引起的。
node.get
,view.get
andsystem.connect
use different permissions thannode.save
. Its likely that they are all authorized for the anonymous user whilenode.save
isn't. Since you mentionsystem.connect
, I guess you already try to start an authenticated session before callingnode.save
. Are you sure the session is properly maintained between calls?Also,
This looks more like an exception in the application code handling the server response than an error server-side. It is likely that this is caused by the server returning an HTTP 403 error without a JSON body on access denied.