On Sunday, August 9, 2015 at 10:36:12 AM UTC+1, Zed wrote:
>
> Hello Team,
>
>  
>
> I have a rails web application and have to post a json to the host below. 
>
>  
>
> Presently i am struggling.
>
>  
>
> Can you please help us a with a sample *rails controller method* to push 
> this below notification. 
>
>  
>

net/http is a rather confusing bit of ruby.  You may find using a higher 
level client such as rest client or faraday makes things easier but 
something like the below should do it

req = Net::HTTP::Post.new(uri)
req.body ='...'
req.content_type = 'application.json'

res = Net::HTTP.start(uri.hostname, uri.port) {|http|
  http.request(req)
}

Fred
 

> POST 
> /push?api_key=31fbfefcd4baa21221545c1233cf2631d9e3eca7f6e76b6c486144c115002de0
>  
> HTTP/1.1
>
> Host: https://pushy.me
>
> Content-Type: application/json
>
> Connection: close
>
> Content-Length: 82
>
>  
>
> {"registration_ids":["d62d6163f916d15eed601b"], "data":{"message":"Hello 
> World!"}}
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/34800fdd-d248-4542-987a-7f0657f9575a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to