【发布时间】:2020-09-24 05:06:49
【问题描述】:
我正在尝试使用https://www.gnu.org/software/guile/manual/html_node/Web-Client.html 此处找到的文档将响应数据作为字符串获取。
文档中提到http-request:
返回两个值:从服务器读取的响应,以及 作为字符串、字节向量、#f 值或端口 ....的响应正文。
但是,我不清楚如何实际提取字符串值。我可以得到端口,但不是文档中提到的纯字符串。
(define response
(http-request (string-append "http://localhost:" port "/save")
#:method 'POST
#:headers '((Content-Type . "application/json"))
#:streaming? #f
#:decode-body? #t
#:body (string->utf8 body)))
(response-body-port response)
【问题讨论】:
-
如果你有一个端口并且需要一个字符串,只需使用
port->string