Hi everybody,<div><br><div><div>I'm trying to POST some JSON data to a web service: </div><div><br></div><div>        (ql:quickload :st-json)</div><div>        (ql:quickload :cl-json)</div><div>        (ql:quickload :drakma)</div>
<div><br></div><div>        (defvar *rc* (merge-pathnames (user-homedir-pathname) ".apirc"))</div><div><br></div><div>        (defvar *user*</div><div>          (with-open-file (s *rc*)</div><div>            (st-json:read-json s)))</div>
<div><br></div><div>        (defvar api-url (st-json:getjso "url" *user*))</div><div>        (defvar api-key (st-json:getjso "key" *user*))</div><div>        (defvar api-email (st-json:getjso "email" *user*))</div>
<div><br></div><div>        (setf drakma:*header-stream* *standard-output*)</div><div><br></div><div>        (defvar *req* '(("dataset" . "tigge")</div><div>                  ("step"    . "24")</div>
<div>                  ("date"    . "20071001")</div><div>                  ("time"    . "00")</div><div>                  ("origin"  . "all")))</div><div><br></div>
<div>        (format t "json:~S~%" (json:encode-json-to-string *req*))</div><div><br></div><div>        (defun retrieve (api request)</div><div>          (let* ((cookie-jar (make-instance 'drakma:cookie-jar))</div>
<div>                 (extra-headers (list (cons "From" api-email)</div><div>                                      (cons "X-API-KEY" api-key)))</div><div>                 (url (concatenate 'string api-url api "/requests"))</div>
<div>                 (stream (drakma:http-request url</div><div>                               :additional-headers extra-headers</div><div>                               :accept "application/json"</div><div>                               :method :post</div>
<div>                               :content-type "application/json"</div><div>                               :external-format-out :utf-8</div><div>                               :external-format-in :utf-8</div>
<div>                               :redirect 100</div><div>                               :cookie-jar cookie-jar</div><div>                               :content (json:encode-json-to-string request)</div><div>                               :want-stream t)))</div>
<div>              (st-json:read-json stream)))</div><div><br></div><div>     (retrieve "/datasets/tigge" *req*)</div><div><br></div><div>Unfortunately, I get an error, although the data seems to be encoded OK to JSON and the headers generated by drakma too, I think. Apparently something is wrong with the :content (the list of integers in the errors message is just the list of ASCII codes of the JSON encoded data).</div>
<div><br></div><div>    json:"{\"dataset\":\"tigge\",\"step\":\"24\",\"number\":\"all\",\"levtype\":\"sl\",\"date\":\"20071001\",\"time\":\"00\",\"origin\":\"all\",\"type\":\"pf\",\"param\":\"tp\",\"area\":\"70\\/-130\\/30\\/-60\",\"grid\":\"2\\/2\",\"target\":\"data.grib\"}"</div>
<div><br></div><div>    POST /v1/datasets/tigge/requests HTTP/1.1</div><div>    Host: <a href="http://api.service.int">api.service.int</a></div><div>    User-Agent: Drakma/1.3.0 (SBCL 1.1.5; Darwin; 12.2.0; <a href="http://weitz.de/drakma/">http://weitz.de/drakma/</a>)</div>
<div>    Accept: application/json</div><div>    Connection: close</div><div>    From: <a href="mailto:me@gmail.com">me@gmail.com</a></div><div>    X-API-KEY: 19a0edb6d8d8dda1e6a3b21223e4f86a</div><div>    Content-Type: application/json</div>
<div>    Content-Length: 193</div><div><br></div><div><br></div><div>    debugger invoked on a SIMPLE-TYPE-ERROR:</div><div>      The value of CL+SSL::THING is #(123 34 100 97 116 97 115 101 116 34 58 34</div><div>                                  ...), which is not of type (SIMPLE-ARRAY</div>
<div>                                                              (UNSIGNED-BYTE 8)</div><div>                                                              (*)).</div><div><br></div><div>Any idea what's wrong with this code? Many thanks in advance.</div>
<div><br></div><div>Best regards,</div></div></div><div>Piotr</div>