all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* HTTP POST requests with url.el
@ 2006-10-20 17:19 Tassilo Horn
  2006-10-20 18:59 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Tassilo Horn @ 2006-10-20 17:19 UTC (permalink / raw)


Hi,

I'm rewriting my emms-lastfm plugin to use url.el instead of the
unmaintained http-{get,post}.el. But I don't get the track submission
via HTTP POST working.

Here's my code:

--8<---------------cut here---------------start------------->8---
(defun emms-lastfm-submit-track ()
  "Submits the current track (`emms-lastfm-current-track') to
last.fm."
  (interactive)
  (let* ((artist (emms-track-get emms-lastfm-current-track 'info-artist))
         (title  (emms-track-get emms-lastfm-current-track 'info-title))
         (album  (emms-track-get emms-lastfm-current-track 'info-album))
         (musicbrainz-id "")
         (track-length (number-to-string
                        (emms-track-get emms-lastfm-current-track
                                        'info-playing-time)))
         (date (format-time-string "%Y-%m-%d %H:%M:%S" (current-time) t))
         (url-http-attempt-keepalives nil)
         (url-request-method "POST")
         (url-request-data (concat "u=" emms-lastfm-username
                                   "&s=" (md5 (concat
                                               (md5 emms-lastfm-password)
                                               emms-lastfm-md5-challenge))
                                   "&a[0]=" artist
                                   "&t[0]=" title
                                   "&b[0]=" album
                                   "&m[0]=" musicbrainz-id
                                   "&l[0]=" track-length
                                   "&i[0]=" date "\r\n")))
    (setq emms-lastfm-buffer
          (url-retrieve emms-lastfm-submit-url
                        'emms-lastfm-submission-sentinel))))

(defun emms-lastfm-submission-sentinel ()
  "Is called after a track submission to last.fm was made."
  (save-excursion
    (set-buffer emms-lastfm-buffer)
    (if (re-search-forward "OK" nil t 2)
        (message "\"%s\" submitted..."
                 (emms-track-description emms-lastfm-current-track))
      ;; TODO: Inform the user what went wrong.
      (message "Song couldn't be submitted"))))
--8<---------------cut here---------------end--------------->8---

When the request is done I get this in *URL-DEBUG*:

,----
| http -> Contacting host: 62.216.251.205:80
| http -> Marking connection as busy: 62.216.251.205:80 #<process 62.216.251.205>
| http -> Request is: 
| POST /protocol_1.1 HTTP/1.1
| MIME-Version: 1.0
| Connection: close
| Extension: Security/Digest Security/SSL
| Host: 62.216.251.205
| Accept-charset: utf-8;q=1, iso-8859-1;q=0.5, iso-8859-15;q=0.5, windows-1252;q=0.5, big5;q=0.5, iso-2022-jp;q=0.5, shift_jis;q=0.5, iso-8859-2;q=0.5, iso-8859-3;q=0.5, iso-8859-4;q=0.5, iso-8859-5;q=0.5, iso-8859-7;q=0.5, iso-8859-8;q=0.5, iso-8859-9;q=0.5, gb2312;q=0.5, euc-jp;q=0.5, euc-kr;q=0.5, tis-620;q=0.5, iso-8859-14;q=0.5, windows-1251;q=0.5, koi8-r;q=0.5, koi8-u;q=0.5, viscii;q=0.5, hz-gb-2312;q=0.5, iso-2022-cn-ext;q=0.5, iso-2022-cn;q=0.5, iso-2022-jp-2;q=0.5, iso-2022-kr;q=0.5, utf-16;q=0.5, utf-16be;q=0.5, utf-16le;q=0.5
| Accept: */*
| User-Agent: URL/Emacs (i686-pc-linux-gnu; X11)
| Content-length: 172
| 
| u=heimdall80&s=7728cf8409b2888f4a5077c26480798f&a[0]=Leonard Cohen&t[0]=Waiting For The Miracle (Edited)&b[0]=Natural Born Killers&m[0]=&l[0]=223&i[0]=2006-10-20 17:09:14
| 
| http -> Calling after change function `url-http-wait-for-headers-change-function' for `#<process 62.216.251.205>'
| http -> url-http-wait-for-headers-change-function ( *http 62.216.251.205:80*)
| http -> Saw end of headers... ( *http 62.216.251.205:80*)
| http -> url-http-parse-response called in ( *http 62.216.251.205:80*)
| http -> No content-length, being dumb.
| http -> url-http-end-of-document-sentinel in buffer ( *http 62.216.251.205:80*)
| http -> Marking connection as free: 62.216.251.205:80 #<process 62.216.251.205>
| http -> url-http-parse-headers called in ( *http 62.216.251.205:80*)
| http -> url-http-parse-response called in ( *http 62.216.251.205:80*)
| http -> Parsed HTTP headers: class=2 status=200
| http -> Finished parsing HTTP headers: t
| http -> Marking connection as free: 62.216.251.205:80 #<process 62.216.251.205>
| http -> Activating callback in buffer ( *http 62.216.251.205:80*)
`----

But the server response tells me there was something wrong with my post
data.

,----
| HTTP/1.1 200 OK
| Server: Apache-Coyote/1.1
| Pragma: no-cache
| Cache-Control: no-cache
| Content-Type: text/plain;charset=ISO-8859-1
| Date: Fri, 20 Oct 2006 17:09:14 GMT
| Connection: close
| 
| FAILED Plugin bug: Not all request variables are set - no POST
| parameters.  INTERVAL 1
`----

Does anyone know what I'm doing wrong, or how I can find the bug?

Bye and thanks,
Tassilo
-- 
[Emacs] is written in Lisp, which is the only computer language that is
beautiful.  -- Neal Stephenson, _In the Beginning was the Command Line_

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-10-24 15:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-20 17:19 HTTP POST requests with url.el Tassilo Horn
2006-10-20 18:59 ` Stefan Monnier
2006-10-20 19:34   ` Tassilo Horn
2006-10-20 20:03     ` Tassilo Horn
2006-10-20 22:04   ` Andreas Seltenreich
     [not found]   ` <mailman.48.1161381893.27805.help-gnu-emacs@gnu.org>
2006-10-24 15:44     ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.