It seems the first thing to do is to isolate the problem you are having. A way to do so is to use either a known working server (so you can test the client) or a known working client (so you can test the server). <br><br>
If you use PLT web-server, you should be able to access the post data with request-post-data/raw. See <a href="http://docs.plt-scheme.org/web-server/http.html#%28def._%28%28lib._web-server/http/request-structs..ss%29._request%29%29" target="_blank">http://docs.plt-scheme.org/web-server/http.html#(def._((lib._web-server/http/request-structs..ss)._request))</a><br>
<br>It is unclear what you mean by you "cannot make it work for a POST" - does it throw an error or hangs? <br><br>post-pure-port returns only the data (without the headers), and your usage appears correct below. <br>
<br>Another way of finding out what's posted to the server is to read in the whole request at once - you can use read-bytes and pass a large enough number that you'll for sure the request will not exceed. <br><br>
Above are what I thought of immediately. Cheers,<br>yc<br><br><div class="gmail_quote">On Fri, Aug 28, 2009 at 12:32 PM, <a href="mailto:keydana@gmx.de" target="_blank">keydana@gmx.de</a> <span dir="ltr"><<a href="mailto:keydana@gmx.de" target="_blank">keydana@gmx.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi all,<br>
<br>
I'd be glad for some help with a problem I have reading in a raw POST request and/or the usage of post-pure-port.<br>
I'm developing a small web service client, and I'm faking the corresponding server using the basic server from the More tutorial and adapting it just enough to send the required responses.<br>
<br>
While this works fine for a GET request, I cannot make it work for a POST, and unfortunately I even do not know whether the problem is on the server or the client side...<br>
<br>
>From the client, I use<br>
<br>
(define store-events-to-ws<br>
(lambda (xexpr)<br>
(let ((payload (string->bytes/utf-8 (xexpr->string xexpr))) (request (format "http://~a:~a/calendar/events" *HOSTNAME* *PORT*)))<br>
(let ((response (post-pure-port (string->url request) payload)))<br>
(read-line response)))))<br>
<br>
<br>
In the server, when it's a POST request, I try to parse the content, but I don't get at anything. With a regex like the one below, I get 2 response headers and 2 empty strings:<br>
<br>
POST content is: (#"Host: localhost:6666\r\nContent-Length: 517\r\n\r\n" #"Host: localhost:6666" #"Content-Length: 517" #"" #"")<br>
<br>
When I try to make the regex longer, hoping for some POSTED content, the process hangs.<br>
<br>
<br>
(define handle-request<br>
(lambda (in out)<br>
(let ((req (regexp-match #rx"^(.*) (.+) HTTP/[0-9]+\\.[0-9]+" (read-line in))))<br>
(when req<br>
(let ((method (second req)) (path (third req)))<br>
(let ((posted-content<br>
(if (equal? method "POST")<br>
(regexp-match (byte-regexp #"(.*?)\r\n(.*?)\r\n(.*?)\r\n(.*?)") in)<br>
#f)))<br>
(printf "POST content is: ~s~n" posted-content)<br>
(printf "Requested path is: ~s~n" path)<br>
(printf "Method is: ~s~n" method)<br>
(let ((xexpr (prompt (dispatch path method posted-content))))<br>
(display "HTTP/1.0 200 Okay\r\n" out)<br>
(display "Server: k\r\nContent-Type: text/html\r\n\r\n" out)<br>
(display (xexpr->string xexpr) out)<br>
(printf "Request answered~n"))))))))<br>
<br>
<br>
Now I am a bit clueless how to investigate the problem. Perhaps I am making mistakes with the regex, or the handling of the input port. Or perhaps the POST did not work and there was really nothing...<br>
<br>
I'd be grateful for any advice in this. Of course I can at any time send more chunks of the code.<br>
<br>
Best greetings,<br>
Sigrid<br>
_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>
</blockquote></div><br>