Sending HTTP POST in Racket

限于喜欢 提交于 2019-12-04 09:57:54

In your example, the hostname is only the www.w3.org portion -- not including the scheme (http or https) nor any path. So for example this does work:

(http-conn-open "www.w3.com"
                #:ssl? #t)

To make a post request, you could do this:

#lang racket

(require net/http-client)

(define-values (status headers in)
  (http-sendrecv "www.w3.com"
                 "/"
                 #:ssl? #t
                 #:version "1.1"
                 #:method "POST"
                 #:data "Hello"))
(displayln status)
(displayln headers)
(displayln (port->string in))
(close-input-port in)

In Racket, a function can return multiple values. http-sendrecv returns three, and the define-values assigns each one to a variable.

net/http-client provides other functions to let you make a connection to a host, make multiple requests on that connection, then close the connection.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!