Sending HTTP POST to Racket

I am trying to send a string via http / post to Racket, this is what I have tried so far after reading the Racket HTTP Client Documentation

#lang racket

(require net/http-client)

(define
  myUrl "https://something.com")

(http-conn-send!
   (http-conn-open
    myUrl
    #:ssl? #t)
   #:version "1.1"
   #:method "POST"
   #:data "Hello")

But with this, I get the following error:

tcp-connect: connection failed
  detail: host not found
  address: https://www.w3.org/
  port number: 443
  step: 1
  system error: nodename nor servname provided, or not known; errno=8

I tried it with several different addresses.

I am new to racket and programming in general and cannot understand what is missing.

+4
source share
1 answer

In your example, the host name is only part www.w3.org— not including the scheme (http or https), nor any path. So, for example, this works:

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

To make a mail request, you can 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)

Racket . http-sendrecv , define-values .

net/http-client , , , .

+8

All Articles