1 Reply Latest reply on Sep 12, 2013 7:29 AM by Kutir Mobility

    Can i use AsyncHttp.post in a custom module/class?

      Hi,

      i am trying to use the AsyncHttp.post inside a custom module within my application. however i am having issues setting the callback parameter for the request.

      when i specify the callsign parameter as :

                      Rho::AsyncHttp.post(
                      :url => "http://localhost:4534/wcfservice/",
                      :headers => { "Content-Type" => "application/json; charset=utf-8", "Content-Length" => data.length },
                      :body => data,
                      #            :ssl_verify_peer => false,
                      :callback => url_for(:action => :mycallback)
                      )
      

      i get the following error:

      undefined method `url_for' for MyModuleName:Module
      

       

      if i change the callback parameter to remove the url_for:

                      Rho::AsyncHttp.post(
                      :url => "http://localhost:4534/wcfservice/",
                      :headers => { "Content-Type" => "application/json; charset=utf-8", "Content-Length" => data.length },
                      :body => data,
                      #            :ssl_verify_peer => false,
                      :callback => :mycallback
                      )
      

       

      the request is received on the server, however i get the following error:

      E 09/12/2013 15:04:30:276 00001588           HttpServer| The file /mycallback was not found
      E 09/12/2013 15:04:30:276 00000514                  Net| An error occured connecting to the server: 404 returned.
      

       

      what do i need to change to correct this problem?

      although i haven't tried it as yet, i would also like to make use of Rho::Timer in my module, and guess would run into similar problem when specifying the callback.

       

      thanks.

        • Re: Can i use AsyncHttp.post in a custom module/class?
          Kutir Mobility

          url_for is a helper declared in the RhoController class, so it's only available inside controller methods. There are two things you can do if you need to set a callback from somewhere else:

           

          - call url_for in a controller and pass the result as a parameter to your module. This would be the preferred approach, as it will make different parts of your code more decoupled from each other.

          - you can simply hardcode the url and use "/app/MyController/mycallback". It's not particularly elegant, but it will work.

           

          Javier

          Kutir Mobility