I can't work out how you pass arguments to an http post request with trivial-http library. I can make a post but I'm not sure how to pass post variables. as a character stream.
http://common-lisp.net/project/trivial-http/user-guide.html#http-post
I can't work out how you pass arguments to an http post request with trivial-http library. I can make a post but I'm not sure how to pass post variables. as a character stream.
http://common-lisp.net/project/trivial-http/user-guide.html#http-post
You should encode the POST body as a string. See http://en.wikipedia.org/wiki/POST_(HTTP) for example. To make character stream from string, use with-input-from-string or make-string-stream.
You need to pass the post variables in as the content of the post request. The most common way is as application/x-www-form-urlencoded
, though multipart/form-data
can be used if you need to do file uploads; see here for details on the encodings.
To pass information in a POST request using application/x-www-form-urlencoded
, you need to pass that in as the content type, and a url-encoded query string as the content. Something like this should work:
(thttp:http-post "http://example.com/submit-form" "application/x-www-form-urlencoded"
"foo=bar&baz=quux")
If you need to escape strings that will be passed in as keys or values for the POST requests, then you can use escape-url-query
to escape them to be safe to pass in in a url-encoded body:
(thttp:http-post "http://example.com/submit-form" "application/x-www-form-urlencoded"
(format nil "foo=~a&bar=~a" (thttp:escape-url-query foo)
(thttp:escape-url-query bar))))