在emacs:utf-8问题中使用url elisp包创建POST

我目前正在创建一个Rest客户端,用于以pastie.el的精神制作博客文章。 主要目标是让我在emacs中编写一个纺织品,然后发布一个创建它的Rails应用程序。 它工作正常,直到我输入任何西class牙语或日语,然后我得到500错误。 pastie.el也有同样的问题。

这是代码:

(要求’url)

(defun create-post() (interactive) (let ((url-request-method "POST") (url-request-extra-headers '(("Content-Type" . "application/xml"))) (url-request-data (concat "" "" "" "Not working with spanish nor japanese" "" "" ;; "日本語" ;; not working ;; "ñ" ;; not working either "h1. Textile title\n\n" "*Textile bold*" "" "")) ) ; end of let varlist (url-retrieve "http://127.0.0.1:3000/posts.xml" ;; CALLBACK (lambda (status) (switch-to-buffer (current-buffer))) ))) 

我现在可以想象的唯一方法就是修复问题的方法是让emacs编码utf-8字符,这样”’变成’&#241’(顺便说一句)。

什么可以解决这个问题?

编辑:’*’不等于*’。 我的意思是,如果我使用例如’sgml-char’的emacs编码为utf-8,它将使整个post变为utf-8编码。 像* Textile bold *因此使RedCloth无法将其转换为html。 对不起,解释得非常糟糕。

猜测:如果你将url-request-data设置为,它是否有效

 (encode-coding-string (concat " 

代替?

没有什么可以告诉url你使用什么编码系统,所以我猜你必须自己编码你的数据。 这也应该给出一个正确的Content-length头,因为它只来自(length url-request-data) ,这显然会给大多数UTF-8字符串带来错误的结果。

感谢@legoscia我现在知道我必须自己编码数据。 我将在此处发布此function以供将来参考:

 (require 'url) (defun create-post() (interactive) (let ((url-request-method "POST") (url-request-extra-headers '(("Content-Type" . "application/xml; charset=utf-8"))) (url-request-data (encode-coding-string (concat "" "" "" "Not working with spanish nor japanese" "" "" "日本語\n\n" ;; working!!! "ñ\n\n" ;; working !!! "h1. Textile title\n\n" "*Textile bold*" "" "") 'utf-8) ) ) ; end of let varlist (url-retrieve "http://127.0.0.1:3000/posts.xml" ;; CALLBACK (lambda (status) (switch-to-buffer (current-buffer)) )))) ;let 
Interesting Posts