我正在使用以下代码来获取 url http://brandonhsiao.com/essays.html
:
(defparameter *new-line* '(#\Return #\Newline))
(defun read-url (host port path)
(let ((sock (usocket:socket-connect host port)))
(format (usocket:socket-stream sock) "~A"
(concatenate 'string
"GET " path " HTTP/1.1" *new-line*
"Connection: close" *new-line* *new-line*))
(force-output (usocket:socket-stream sock))
(do ((line
(read-line (usocket:socket-stream sock) nil)
(read-line (usocket:socket-stream sock) nil))
(all ""))
((not line) all)
(setf all (concatenate 'string all line *new-line*)))))
(print (read-url "brandonhsiao.com" 80 "/essays.html"))
这给了我一个400 Bad Request
错误,但是当我http://brandonhsiao.com/essays.html
使用 Firefox 访问时,一切都很好。我究竟做错了什么?