HTTP 之 OPTIONS 請求

OPTIONS: 用來詢問服務器支持哪些方法。

HTTP1.1 規範要求,必須包含 HOST 頭部,服務器通過 Allow 頭關返回服務器支持的方法, 一般包體爲空。常規方法有 GET,POST,HEAD,TRACE,OPTIONS,默認情況下 IIS 不支持 PUT,DELETE。

CLISP  實現如下:

(defun http-options (url)
(let ((host nil)(rel-url nil))
(let* ((s (+ 3 (search "://" url)))
   (e (search "/" url :start2 s)))


(setf host (subseq url s e)
rel-url (subseq url e)))
(cli-init)
(http-write (format nil "OPTIONS ~a HTTP/1.1" rel-url))
(http-write (format nil "Host: ~a" host))
(http-write "Accept: *")
(http-write +newline+ nil)

(when *conn*
(http-stream-mode nil)
(let* ((tmp-list (loop for x = (http-read-line)
while (and x (plusp (length x)))
collect x))
   (content-length (get-content-length tmp-list)))
   
(http-stream-mode t)
;讀取返回內容
(format nil
"~{~a~%~}~a~%"
tmp-list
(decode-bytes (loop for i from 0 to (1- content-length) for x = (http-read-byte) while x collect x)

*html-charset*))))))

執行結果截圖:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章