Hi,
To send data from an action I do this:
def send_mydata
...
uri = URI.parse(link)
net_http = Net::HTTP.new(uri.host, uri.port)
net_http.open_timeout = timeout
net_http.read_timeout = timeout
net_http.use_ssl = (uri.scheme == 'https')# enable SSL/TLS
if net_http.use_ssl?
net_http.cert =
OpenSSL::X509::Certificate.new(File.read(cert_path))
net_http.key = OpenSSL::PKey::RSA.new(File.read(key_path))
net_http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
self.response_body = proc do |response, output|
net_http.start do |http|
http.request_get(uri.request_uri()) do |res|
case res
when Net::HTTPSuccess then
res.read_body do |segment|
response.write(segment)
end
when Net::HTTPRedirection then
response.close() unless response.closed?
return
else
raise "Net::HTTPResponse error: #{res.message.to_s()}"
end
end
end
end
end
On Mar 1, 5:50 am, gs84 <salimat...@gmail.com> wrote:
> On 28 fév, 21:30, Bill Walton <bwalton...@gmail.com> wrote:
>
> > I use the Ruby Net::HTTP library to construct requests.
>
> > Best regards,
> > Bill
>
> Thanks to all for your answer.
> Bill, can you show me please how you you use the NET::HTTP library to
> call web service.
>
> Because i have used the NET::HTTP libray like the following, but i
> alway got 405 error and web service is not called.
> I have the signup method in my user controller!
>
> def signup
> require "net/http"
> require "uri"
>
> user= User.new(params[:firstname],
> params[:lastname],params[:password],params[:mobilenumber],params[:email])
> uri = URI.parse("myWebServiceUrl")
> http = Net::HTTP.new(uri.host, uri.port)
>
> request = Net::HTTP::Post.new(uri.request_uri)
> request.set_form_data({ "password" =>
> "MyPassword","firstname"=>"yourFirstname", "lastname"=>"yourLatsname",
> "email"=>"em...@yahoo.com","mobilenumber"=>"1234567890"})
> response, data = http.request(request)
>
> render :text => "#{data}"
> end
>
> Thanks for your help
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment