<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi,</div><div><br></div><div>thanks a lot for your advice! I tried read-bytes and it worked - I see the posted request, it is there!</div><div><br></div><div>So now it only remains for me to find out what I did wrong with regex, just for fun/curiosity/learning :-;</div><div><br></div><div>BTW just as an aside, I was also planning to use the web server as a last resort, just it was easier for me to extend the code from the More tutorial as I have worked through this not-too-long-ago and of course again, I was curious to experiment &nbsp;with this basic &amp; raw server implementation :-;</div><div><br></div><div>So thanks again, this saved me quite some hours!</div><div>Sigrid</div><div><br></div><div><br></div><div><br></div><br><div><div>Am 28.08.2009 um 22:03 schrieb YC:</div><br class="Apple-interchange-newline"><blockquote type="cite">It seems the first thing to do is to isolate the problem you are having.&nbsp; 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.&nbsp; 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.&nbsp; <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.&nbsp; <br><br> Above are what I thought of immediately.&nbsp; 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">&lt;<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> &nbsp;(lambda (xexpr)<br> &nbsp; &nbsp;(let ((payload (string->bytes/utf-8 (xexpr->string xexpr))) (request (format "http://~a:~a/calendar/events" *HOSTNAME* *PORT*)))<br> &nbsp; &nbsp; &nbsp;(let ((response (post-pure-port (string->url request) payload)))<br> &nbsp; &nbsp; &nbsp; &nbsp;(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> &nbsp;(lambda (in out)<br> &nbsp; &nbsp; (let ((req (regexp-match #rx"^(.*) (.+) HTTP/[0-9]+\\.[0-9]+" (read-line in))))<br> &nbsp; &nbsp; &nbsp;(when req<br> &nbsp; &nbsp; &nbsp; &nbsp;(let ((method (second req)) (path (third req)))<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(let ((posted-content<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (if (equal? method "POST")<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(regexp-match (byte-regexp #"(.*?)\r\n(.*?)\r\n(.*?)\r\n(.*?)") in)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #f)))<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(printf "POST content is: ~s~n" posted-content)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(printf "Requested path is: ~s~n" path)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(printf "Method is: ~s~n" method)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(let ((xexpr (prompt (dispatch path method posted-content))))<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(display "HTTP/1.0 200 Okay\r\n" out)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(display "Server: k\r\nContent-Type: text/html\r\n\r\n" out)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(display (xexpr->string xexpr) out)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(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> &nbsp; &nbsp; &nbsp; &nbsp;_________________________________________________<br> &nbsp;For list-related administrative tasks:<br> &nbsp;<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></blockquote></div><br></body></html>