mobgambo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-14 17:46 UTC
Reading http request as IO in rails
Hi, Here''s what i''m trying to do my mobile phone app ( j2me) tries to connect to the my rails application. the j2me app opens a java.io.OutputStream here''s the snippet hc = (HttpConnection) Connector.open(UPDATE_URL, Connector.READ_WRITE); hc.setRequestMethod(HttpConnection.POST); hc.setRequestProperty("If-Modified-Since", "29 Oct 1999 19:43:31 GMT"); hc.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.2"); hc.setRequestProperty("Content-Language", "en-US"); out = hc.openOutputStream(); j2me app then just writes data to the output stream(pretty basic here). so far so good. not a problem here. And on my rails controller i do the following, class MainController < ApplicationController def read_data url = request.env["REQUEST_URI"] method = request.env["REQUEST_METHOD"] data = request.env["RAW_POST_DATA"] newf = File.open("MY_DATA", "wb") str = request.body.read newf.write(str) newf.close render :text => "Hello Load #{url}" end end the problem is the same j2me app works(only changes the url) if i have a servlet receiving the data, i do request.getInputStream on a servlet and everything works. But on rails i get ioexception under j2me app saying couldn''t write to socket. Also is request.body.read the correct way to do it. ? Is this possible in rails or am i making the wrong assumptions here ? what am i doing wrong, or rather how is it done. I appreciate any insights that you may have. mb --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
mobgambo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-15 03:49 UTC
Re: Reading http request as IO in rails
Anybody, any pointers. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, Here''s what i''m trying to do my mobile phone app ( j2me) tries to connect to the my rails application. the j2me app opens a java.io.OutputStream here''s the snippet hc = (HttpConnection) Connector.open(UPDATE_URL, Connector.READ_WRITE); hc.setRequestMethod(HttpConnection.POST); hc.setRequestProperty("If-Modified-Since", "29 Oct 1999 19:43:31 GMT"); hc.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.2"); hc.setRequestProperty("Content-Language", "en-US"); out = hc.openOutputStream(); j2me app then just writes data to the output stream(pretty basic here). so far so good. not a problem here. And on my rails controller i do the following, class MainController < ApplicationController def read_data url = request.env["REQUEST_URI"] method = request.env["REQUEST_METHOD"] data = request.env["RAW_POST_DATA"] newf = File.open("MY_DATA", "wb") str = request.body.read newf.write(str) newf.close render :text => "Hello Load #{url}" end end the problem is the same j2me app works(only changes the url) if i have a servlet receiving the data, i do request.getInputStream on a servlet and everything works. But on rails i get ioexception under j2me app saying couldn''t write to socket. Also is request.body.read the correct way to do it. ? Is this possible in rails or am i making the wrong assumptions here ? what am i doing wrong, or rather how is it done. I appreciate any insights that you may have. mb -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
So i should take it that this is not possible in rails ? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---