Rubén Parés-Selders: July 2008 Archives

Lets Post something..

| | Comments (0) | TrackBacks (0)

..and create a Ruby / Webrick Webserver that receives post and gets in seconds:

require ‘webrick’ include WEBrick

class CurrentTimeServlet < WEBrick::HTTPServlet::AbstractServlet

def doGET(request, response) response[‘Content-Type’] = ‘text/plain’ response.status = 200 response.body = Time.now.tos + “\n” end

def do_POST(request, response) puts request.body end end

———————————————————————

Create an HTTP server

s = HTTPServer.new( :Port => 8000 )

s.mount(“/logreceiver”, CurrentTimeServlet)

When the server gets a control-C, kill it

trap(“INT”){ s.shutdown }

Start the server

s.start

http://www.linuxjournal.com/article/8356

About this Archive

This page is a archive of recent entries written by Rubén Parés-Selders in July 2008.

Rubén Parés-Selders: June 2008 is the previous archive.

Rubén Parés-Selders: November 2009 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Rubén Parés-Selders: Monthly Archives

Powered by Movable Type 4.0