Posted By

bcmoney on 12/10/10


Tagged

http LISP proxy


Versions (?)

proxy.lisp


 / Published in: Lisp
 

URL: http://bcmoney-mobiletv.com/blog/2009/05/01/the-server-side-proxy/

http://cl-cookbook.sourceforge.net/sockets.html#example

  1. (defun http-get (server port path)
  2. "Send a request for file `path' to an HTTP/0.9 server on host
  3. `server', port number `port'. Print the contents of the returned file
  4. to standard output."
  5. ;; Open connection
  6. (let ((socket (open-socket server port)))
  7. (unwind-protect
  8. (progn
  9. (format t "> Sending request to ~a:~a...~%" server port)
  10. ;; Send request
  11. (http-send-line socket (format nil "GET ~a HTTP/0.9~%~%" path))
  12. (force-output socket)
  13.  
  14. ;; Read response and output it
  15. (format t "> Received response:~%")
  16. (loop
  17. (let ((line (read-line socket nil nil)))
  18. (unless line (return))
  19. (format t "~a~%" line))))
  20.  
  21. ;; Close socket before exiting.
  22. (close socket))))

Report this snippet  

You need to login to post a comment.