On Tue, 23 Aug 2016 02:09:24 -0700 (PDT), Normal Loone
<andreas.m.wi...@gmx.de> wrote:

>Yeah, my main problem is how do I pack the file into a JSON Object
>and then send it?

Just FYI: JSON is a printable coding, so any non-printable characters
in a binary file must be escaped - making the transfer larger.

The read-json and write-json functions take care of escaping, but if
you are sending large files, the overhead may be significant.


>With (require net/http-client) I could already establish a connection
>with (http-conn-sendrecv! hc uri), but All I can send is the empty
>header of the http request. 
>
>How do I add the HTML code or the file in the json object within it?

If I understand correctly, you're trying to send the file to a server
via HTTP from a Racket client.

If the file is JSON encoded, you can send it as a simple HTTP
parameter: e.g.,

(require net/http-client
         net/uri-codec)

(let [
      (params 
       (alist->form-urlencoded
        (list (cons 'file (write-bytes  your-file-data ))
              )))
      (headers
       (list "Content-Type: application/x-www-form-urlencoded")
       )
     ]

  (let-values
      [
       ((resp-code resp-hdrs port)
        (http-sendrecv host
                       url
                       #:method #"POST"
                       #:data params
                       #:headers headers 
                       ))
      ]  
    (printf "~s~n~s~n~s~n"
            resp-code
            resp-hdrs
            (port->bytes port))
   ))


Sending binary file data or extremely long files (that can't be loaded
fully into memory) requires an HTTP multipart form. 

Multipart forms are complex to encode: they have opening headers,
boundary markers enclosing and sometimes interspersed with the data,
and closing footers after the data.  I don't have a ready example.
For more information see http://www.rfc-base.org/rfc-1867.html

Hope this helps,
George

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to