(define (rpc-test hostname path name . values)
  (let ((port (open-tcp-stream-socket hostname "www"))
        (entity
         (xml->string
          (rpc-elt:method-call
           (rpc-elt:method-name name)
           (rpc-elt:params
            (map (lambda (v)
                   (rpc-elt:param (xml-rpc:encode-value v)))
                 values))))))
    (write-string "POST " port)
    (write-string path port)
    (write-string " HTTP/1.0" port)
    (newline port)
    (write-string "host: " port)
    (write-string hostname port)
    (newline port)
    (write-string "content-type: text/xml" port)
    (newline port)
    (write-string "content-length: " port)
    (write (string-length entity) port)
    (newline port)
    (newline port)
    (write-string entity port)
    (flush-output port)
    (let loop ()
      (let ((c (read-char port)))
        (if (not (eof-object? c))
            (begin
              (write-char c)
              (loop)))))))

(rpc-test "localhost" "/projects/scheme-pages/xmlrpc/test_params"
          "test_params" 2 3)
