[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
do and read-line in MrEd.
Hi,
I have the following procedure which I use in MrEd:
(define (grab-html b e)
(define url (send urlbox get-value))
(let-values ;;(((url) (send urlbox get-value))
(((sin sout) (tcp-connect url 80))
((html-start) (regexp "Content-Type:.*")))
(fprintf sout "GET http://www.~s HTTP/1.0~n~n" url)
;; read until "Content-Type..." is met
(do ((line (read-line sin) (read-line sin)))
((not (regexp-match html-start line))))
;; `line' should now equal "Content-Type:..."
;; so I need to read past it
(read-line sin)
(read-line sin) ;; once more for the blank line
;; print the actual source
(do ((line (read-line sin) (read-line sin)))
((eof-object? line)) (printf "~s~n" line))))
It's supposed to grab the HTML found in `url.' In order to do this, I
must read through all the headers that are sent back when doing "GET
<url> HTTP1/.0\n\n" and print out all the lines from the line
beginning with "Content-type:" until EOF. Assuming I run this
procedure on the host underlevel.net, which has the following HTML
source (as seen by tcp-connect):
HTTP/1.1 200 OK
Date: Mon, 02 Jul 2001 22:29:25 GMT
Server: Apache/1.3.4 (Unix) FrontPage/4.0.4.3 PHP/3.0.14
Last-Modified: Fri, 18 May 2001 22:02:12 GMT
ETag: "12881c-3b-3b059be4"
Accept-Ranges: bytes
Content-Length: 59
Connection: close
Content-Type: text/html
<pre>
underlevel.net
==============
Free the text.
</pre>
The function prints:
"
"
"
"
"
"
"
"
"
"
"<pre>"
"underlevel.net"
"=============="
""
"Free the text."
"</pre>"
I cannot figure out where the preceding empty lines come from, or how
to fix it. Can someone please advise?
Thanks a lot,
--
Jordan Katz <katz@underlevel.net> | Mind the gap