0
我正在使用RhoMobile 4.0的应用程序工作。我想知道,如何在没有rhoconnect的情况下连接到rhomobile 4.0的Web服务。需要做http post并得到。使用RhoMobile 4.0直接连接到Web服务
我正在使用RhoMobile 4.0的应用程序工作。我想知道,如何在没有rhoconnect的情况下连接到rhomobile 4.0的Web服务。需要做http post并得到。使用RhoMobile 4.0直接连接到Web服务
使用RhoMobile,您可以使用通常的AJAX方法来访问Web服务来获取或发布数据。
此外,您可以使用Ruby或JavaScript中的RhoMobile Network API来调用Web服务,注册回调。
例如,在Ruby中,你可以有这样的代码在一个控制器:
def getData
#Perform an HTTP GET request.
getProps = Hash.new
getProps['url'] = "http://<my_url>/Json/Server/GetDada?username=admin&password=pass"
getProps['headers'] = {"Content-Type" => "application/json"}
Rho::Network.get(getProps, url_for(:action => :get_callback))
render :action => :transferring
end
def get_callback
if @params['status'] == "ok"
get_result = Rho::JSON.parse(@params['body'])
puts "**** Parsed it" #{@params['body']}"
# Do something with the data
end
end