[drakma-devel] Changing content-type seems to have no effect
Michael Minerva
minerva at agentsheets.com
Thu Mar 15 23:24:37 UTC 2012
Hey Edi,
Thank you so much for your response.
I am now thinking my problem may have something to do with the encoding will the file be encoded using base64 (with multipart/form-data)? Is this something you can set? Is this what external-format-out is for?
Thanks again,
--Mike
On Mar 15, 2012, at 3:08 PM, Edi Weitz wrote:
> If you want to use the content type
> "application/x-www-form-urlencoded", you can only use strings as
> values in the parameter list. You could, if you insist, read your
> file into a string if it's not too big. I have to say that this all
> sounds wrong, though.
>
> Edi.
>
> On Thu, Mar 15, 2012 at 6:53 PM, Michael Minerva
> <minerva at agentsheets.com> wrote:
>> I have been trying to get my lisp application to interface and upload a file to my drupal 7 website using Drakma.
>>
>> So far I have been able to to connect to my drupal site and authenticate and store the session cookie (thank you Ryan Davis, I just found your response the other day). Here is the code I use to do that:
>>
>> (with-output-to-string (stream)
>> (setf drakma:*header-stream* stream)
>> (let ((cookie-jar (make-instance 'drakma:cookie-jar)))
>> (drakma:http-request
>> "http://localhost:8888/?q=rest/user/login"
>> :method :post
>> :cookie-jar cookie-jar
>> :parameters
>> '(("username" . "login")
>> ("password" . "password"))
>> )
>> (drakma:http-request
>> "http://localhost:8888/?q=rest/file"
>> :method :post
>> :cookie-jar cookie-jar
>> :content-length t
>> :parameters '(("file1" . #p"/Users/Mike/hello.png"));("file1" #p"/Users/Mike/Desktop/mario-gif.gif" :content-type "image/gif" :filename "mario-gif.gif"))
>> :content-type "application/x-www-form-urlencoded"
>> ;:parameters
>> )))
>>
>>
>> This code successfully sends both posts but the second post does not actually upload the file (but it does return 200 OK, no errors). I have successfully uploaded to by drupal site using PHP Curl and in that code, I was only able to get it to work by using a content type of application/x-www-form-urlencoded (if I use a multipart/form-data request on my php page I get similar behavior to what I am now seeing with Drakma). This is why I added the line :content-type "application/x-www-form-urlencoded" to my second request (posted above) but it seems to have no effect.
>>
>> Here is a copy of the posts I am making (as you can see in the second post it still uses multipart/form-data. Is there anyway that I can upload a file using Drakma using a content-type of application/x-www-form-urlencoded (I know this is not the recommended way of making this type of request but I think it may be the only way that my drupal site will accept the file).
>>
>> "POST /?q=rest/user/login HTTP/1.1
>> Host: localhost:8888
>> User-Agent: Drakma/1.2.3 (Clozure Common Lisp Version 1.7-r14927M (DarwinX8664); Darwin; 10.8.0; http://weitz.de/drakma/)
>> Accept: */*
>> Connection: close
>> Content-Type: application/x-www-form-urlencoded
>> Content-Length: 34
>>
>> HTTP/1.1 200 OK
>> Date: Thu, 15 Mar 2012 17:49:51 GMT
>> Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.6
>> X-Powered-By: PHP/5.3.6
>> Expires: Sun, 19 Nov 1978 05:00:00 GMT
>> Last-Modified: Thu, 15 Mar 2012 17:49:51 +0000
>> Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
>> ETag: \"1331833791\"
>> Vary: Accept
>> Set-Cookie: SESSdc0685ed01f285dab628a3700259e6bc=oIJFlVrfoXi-PO7bdwKtauKfTeRSEK1iIucj0tl12UQ; expires=Sat, 07-Apr-2012 21:23:12 GMT; path=/; HttpOnly
>> Content-Length: 115
>> Connection: close
>> Content-Type: text/yaml
>>
>> POST /?q=rest/file HTTP/1.1
>> Host: localhost:8888
>> User-Agent: Drakma/1.2.3 (Clozure Common Lisp Version 1.7-r14927M (DarwinX8664); Darwin; 10.8.0; http://weitz.de/drakma/)
>> Accept: */*
>> Cookie: SESSdc0685ed01f285dab628a3700259e6bc=oIJFlVrfoXi-PO7bdwKtauKfTeRSEK1iIucj0tl12UQ
>> Connection: close
>> Content-Type: multipart/form-data; boundary=----------ndnZ9xjDrDpzStPEQo97xwqPHEKXAhAOd8Ho6C8P3jtKbvNINm
>> Content-Length: 244958
>>
>> HTTP/1.1 200 OK
>> Date: Thu, 15 Mar 2012 17:49:52 GMT
>> Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.6
>> X-Powered-By: PHP/5.3.6
>> Expires: Sun, 19 Nov 1978 05:00:00 GMT
>> Last-Modified: Thu, 15 Mar 2012 17:49:52 +0000
>> Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
>> ETag: \"1331833792\"
>> Vary: Accept
>> Content-Length: 4
>> Connection: close
>> Content-Type: text/yaml
>>
>> "
>>
>> Thanks,
>>
>> --Michael
>>
>>
>> _______________________________________________
>> drakma-devel mailing list
>> drakma-devel at common-lisp.net
>> http://lists.common-lisp.net/cgi-bin/mailman/listinfo/drakma-devel
>
> _______________________________________________
> drakma-devel mailing list
> drakma-devel at common-lisp.net
> http://lists.common-lisp.net/cgi-bin/mailman/listinfo/drakma-devel
>
More information about the Drakma-devel
mailing list