guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Questions about the (web client) module.


From: Mark H Weaver
Subject: Re: Questions about the (web client) module.
Date: Fri, 21 Jul 2017 00:49:36 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

Roel Janssen <address@hidden> writes:

>>> Then my next question is about "multipart/form-data" content types.
>>> My code looks like this:
>>>
>>>   #:headers `((content-type . ,(string-append
>>>                                 "multipart/form-data; boundary=" boundary))
>>>               (Accept . "*/*"))
>>>
>>> But that does not work:
>>>   scheme@(guile-user)> 
>>>   web/request.scm:184:10: In procedure build-request:
>>>   web/request.scm:184:10: Bad request: Bad value for header content-type: 
>>> "multipart/form-data; boundary=..."
>>>
>>> This is, however, a valid Content-Type.
>>
>> What’s the value of ‘boundary’?  At first sight it looks good to me:
>
> The value I use is "guile-virtuoso-driver".  All of the below
> functions work as expected with this value.
>
> Could it be that something else is wrong?
> Here's the entire code I use:
>
> (define* (sparql-query-post query
>                        #:key
>                        (host "localhost")
>                        (port 8890)
>                        (graph "")
>                        (type "json"))
>   (let ((base-uri (string-append "http://"; host ":" (number->string port) ))
>         (boundary "guile-virtuoso-driver"))
>     (let ((body (string-append
>                  (format #f
>                   "--~a~%Content-Disposition: form-data; 
> name=~s~%~%text/csv~%"
>                   boundary "format")
>                   (format #f
>                   "--~a~%Content-Disposition: form-data; 
> name=~s~%~%~a~%--~a~%"
>                   boundary "query" query boundary))))
>       (http-post
>        (string-append base-uri "/sparql")
>        #:body body
>        #:headers `((content-length . ,(string-length body))
>                    (content-type . "multipart/form-data; 
> boundary=guile-virtuoso-driver")

The line above should be replaced with this:

  (content-type . (multipart/form-data (boundary . ,boundary)))

>                    (Accept . "*/*"))))))

and this should be:

  (accept . ((*/*)))

These are the "parsed" form of HTTP headers, where the header names are
lowercase symbols and the associated values are not usually strings but
rather a Scheme representation of the value.  See section 7.3.4 (HTTP
Headers) in the Guile manual for more information.

      Mark



reply via email to

[Prev in Thread] Current Thread [Next in Thread]