我在使用 Rhomobile rhodes 时遇到问题,请问有人可以告诉我如何使用 Rho::AsyncHttp 进行 http 发布、获取、放置和删除吗?我已经尝试了几个小时没有成功。
3 回答
这里有一些示例代码可以放在你的 controller.rb 文件中
这是最初的电话
def index
Rho::AsyncHttp.get(
:url => 'http://the.page.you.want.to.get',
:callback => (url_for :action => :httpget_callback),
:callback_param => "" )
render :action => :wait
结尾
上面的代码将启动 httpget_callback 方法(如下),而该方法会关闭并加载 url,它将更改屏幕并加载 wait.erb 文件
def httpget_callback
if @params['status'] != 'ok'
@@error_params = @params
WebView.navigate(url_for :action => :show_error )
else
@html = @params['body']
end
WebView.navigate ( url_for :action => :show_result )
结尾
无需深入探讨 - 返回页面的正文被放置在 @html 变量中希望有所帮助,如果您需要更多帮助,请告诉我。
我有一个获取帖子 res = Rho::AsyncHttp.post(:url => ' http://192.168.1.64/WebServiceTest/Service.asmx/Sumar ') @msg= "Sync http call: #{res }"
http://wiki.rhomobile.com/index.php/RhodesConnectToWebServices
我也经常在 Rhodes 中为 AsyncHttp 的细微差别而苦苦挣扎,所以我还不能自称精通,但我真的觉得有必要提出一个建议:
我发现在调试我的 Rhodes 应用程序时使用 Firefox 的 Firebug 插件非常有用。你可以很容易地把它挂起来!您可以通过将 Web 服务器配置为在特定端口上运行来使用任何浏览器加载您的应用程序。这个设置在rhoconfig.txt
,它被称为local_server_port
。
这特别有用,因为您可以轻松地调查请求/响应的 HTML 和原始数据,并使用控制台运行 javascript 命令并实时使用 DOM 和网页。