Nicolas Lamirault | 1 Jun 2007 12:27
Favicon

POST request and content-type


hello,
i make some tests with Drakma. 
i would  like to change the  content-type of a POST  request, but i've
got always "application/x-www-form-urlencoded" :

CL-USER> (drakma:http-request "http://lisp.org/"
          :method :post :content-type "application/atom+xml")
POST / HTTP/1.1
Host: lisp.org
User-Agent: Drakma/0.7.0 (SBCL 1.0; Linux; 2.6.18-4-486; http://weitz.de/drakma/)
Accept: */*
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0

HTTP/1.1 307 Temporary Redirect
Date: Fri, 01 Jun 2007 10:23:23 GMT
Connection: Close
Server: AllegroServe/1.2.43
Transfer-Encoding: chunked
LOCATION: /index.html

#()
307
((:DATE . "Fri, 01 Jun 2007 10:23:23 GMT") (:CONNECTION . "Close")
 (:SERVER . "AllegroServe/1.2.43") (:TRANSFER-ENCODING . "chunked")
 (:LOCATION . "/index.html"))
#<PURI:URI http://lisp.org>
#<FLEXI-STREAMS:FLEXI-IO-STREAM {AB1AEB9}>
(Continue reading)

Edi Weitz | 1 Jun 2007 13:21
Picon
Favicon

Re: POST request and content-type

On Fri, 01 Jun 2007 12:27:02 +0200, Nicolas Lamirault <lam <at> tuxfamily.org> wrote:

> i would like to change the content-type of a POST request, but i've
> got always "application/x-www-form-urlencoded" :
>
> [...]
>
> someone knows if i make a mistake ? it is a bug ? 

No, it's documented behaviour:

  http://weitz.de/drakma/#content-type

> PS: very good soft !

Thanks... :)
Nicolas Lamirault | 1 Jun 2007 15:52
Favicon

Re: POST request and content-type


thanks a lot

Edi Weitz <edi <at> agharta.de> writes:

> On Fri, 01 Jun 2007 12:27:02 +0200, Nicolas Lamirault <lam <at> tuxfamily.org> wrote:
>
>> i would like to change the content-type of a POST request, but i've
>> got always "application/x-www-form-urlencoded" :
>>
>> [...]
>>
>> someone knows if i make a mistake ? it is a bug ? 
>
> No, it's documented behaviour:
>
>   http://weitz.de/drakma/#content-type
>
>> PS: very good soft !
>
> Thanks... :)
> _______________________________________________
> drakma-devel mailing list
> drakma-devel <at> common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/drakma-devel
>

--

-- 
Nicolas Lamirault
(Continue reading)

Mathias Dahl | 2 Jun 2007 11:44
Picon

Problem with Drakma and character encoding

Hi!

I have a problem with drakma and character encoding. My goal is to
make a small web utility which first GETs some content from a certain
page on my wiki, then optionally adds prepends stuff to this content,
and then POST the new content back. It works as long as only ASCII
characters are involved but fails when I use characters from the
higher part of Latin-1, in my case the Swedish character "ä".

Below I have simplified the code so that it just GETs the old content
and POST it back. What one sees is that the Swedish character is
correctly handled in the GET, I see the "ä" in it's full glory, but
after having posted it back, the content gets corrupt and the next
time I run the function I get an error because of the strange
character.

Ok, enough blabbing, here is the code:

;;;;; code starts here

(defvar *boundary* "-------------------------1852275791466338532535335716")

(defconstant +crlf+ #.(format nil "~C~C" #\Return #\Linefeed))

(defun format-field (name value)
  (format nil "--~a~aContent-Disposition: form-data; name=\"~a\"~a~a~a~a"
          *boundary* +crlf+ name +crlf+ +crlf+ value +crlf+))

(defun foo ()
  (let* ((old-content (drakma:http-request
(Continue reading)

Vodonosov Anton | 4 Jun 2007 08:18
Picon

Re: Problem with Drakma and character encoding

Hi Mathias, try to use (http-request ... :external-format-out :UTF-8 ...)

See http://weitz.de/drakma/#external-format-out

Best regards,
-Anton
Edi Weitz | 4 Jun 2007 08:49
Picon
Favicon

Re: Problem with Drakma and character encoding

On Sat, 2 Jun 2007 11:44:04 +0200, "Mathias Dahl" <mathias.dahl <at> gmail.com> wrote:

> (defvar *boundary* "-------------------------1852275791466338532535335716")
>
> (defconstant +crlf+ #.(format nil "~C~C" #\Return #\Linefeed))
>
> (defun format-field (name value)
>   (format nil "--~a~aContent-Disposition: form-data; name=\"~a\"~a~a~a~a"
>           *boundary* +crlf+ name +crlf+ +crlf+ value +crlf+))

Any reason you're doing all this instead of just using :FORM-DATA?

  http://weitz.de/drakma/#form-data
Mathias Dahl | 4 Jun 2007 11:19
Picon

Re: Problem with Drakma and character encoding

> Hi Mathias, try to use (http-request ... :external-format-out :UTF-8 ...)

Ah, what a relief! :) It works!

Many thanks!

/Mathias
Mathias Dahl | 4 Jun 2007 11:22
Picon

Re: Problem with Drakma and character encoding

> > (defun format-field (name value)
> >   (format nil "--~a~aContent-Disposition: form-data; name=\"~a\"~a~a~a~a"
> >           *boundary* +crlf+ name +crlf+ +crlf+ value +crlf+))
>
> Any reason you're doing all this instead of just using :FORM-DATA?
>
>  http://weitz.de/drakma/#form-data

Yes, but not a very good one; it is a combination of old code, I
previously used S-HTTP-CLIENT but got problems so I switched to DRAKMA
and I tried to leave the code as intact as possible, not looking into
all nice features that DRAKMA might have. I will try that and see how
that works for me.

Thanks for a great package! It feels nice to be able to do stuff in
CL, although I progress quite slowly... :)

/Mathias
Mathias Dahl | 4 Jun 2007 22:46
Picon

Re: Problem with Drakma and character encoding

> > (defun format-field (name value)
> >   (format nil "--~a~aContent-Disposition: form-data; name=\"~a\"~a~a~a~a"
> >           *boundary* +crlf+ name +crlf+ +crlf+ value +crlf+))
>
> Any reason you're doing all this instead of just using :FORM-DATA?
>
>  http://weitz.de/drakma/#form-data

I have now tested this and it works like a charm, so I don't need my
hacks anymore. Yay! :)

I first used the :PARAMETERS keyword without specifying the :FORM-DATA
keyword, and that works as well as providing it. Are there any
drawbacks of NOT using :FORM-DATA when just sending form fields (i.e.
no files)? Note: one of the form fields can be quite large (maybe up
to a thousand characters) sometimes.

Thanks!

/Mathias
Edi Weitz | 4 Jun 2007 22:55
Picon
Favicon

Re: Problem with Drakma and character encoding

On Mon, 4 Jun 2007 22:46:33 +0200, "Mathias Dahl" <mathias.dahl <at> gmail.com> wrote:

> I have now tested this and it works like a charm, so I don't need my
> hacks anymore. Yay! :)

Good... :)

> I first used the :PARAMETERS keyword without specifying the
> :FORM-DATA keyword, and that works as well as providing it. Are
> there any drawbacks of NOT using :FORM-DATA when just sending form
> fields (i.e.  no files)? Note: one of the form fields can be quite
> large (maybe up to a thousand characters) sometimes.

AFAIK there aren't if you're /not/ sending files.  The size of the
request body shouldn't make a difference as it's a POST request
anyway.

The only other difference that comes to mind right now is that with
multipart/form-data you can potentially use different encodings for
different fields.  I never did that, though, and I wouldn't know why
one should do it (and if the receiving end can cope with it).

Oh, one other difference that just occurs to me is that for large
fields Drakma might be a tad faster if you're using :FORM-DATA.  But
you should only care about this if you really have performance
problems.

Gmane