我目前正在创建一个 Rest 客户端,用于本着 Pastie.el 的精神制作博客文章。我的主要目标是在 emacs 中编写一个 Textile 并在 Rails 应用程序中发布一个帖子来创建它。它工作正常,直到我用西班牙语或日语输入任何内容,然后收到 500 错误。顺便说一句,pastie.el 也有同样的问题。
这是代码:
(需要“网址”)
(defun create-post()
(interactive)
(let ((url-request-method "POST")
(url-request-extra-headers '(("Content-Type" . "application/xml")))
(url-request-data (concat "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<post>"
"<title>"
"Not working with spanish nor japanese"
"</title>"
"<content>"
;; "日本語" ;; not working
;; "ñ" ;; not working either
"h1. Textile title\n\n"
"*Textile bold*"
"</content>"
"</post>"))
) ; 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 字符进行编码,这样 'ñ' 就会变成 'ñ' (顺便说一句,这是可行的)。
有什么办法可以解决这个问题?
编辑:'*' 不等于 *'。我的意思是,如果我使用 emacs 使用“sgml-char”编码为 utf-8,那么整个帖子就会变成 utf-8 编码。就像*纺织粗体*从而使得RedCloth无法将其转换为html。抱歉,解释得非常糟糕。
猜测:如果你设置它会起作用吗url-request-data
to
(encode-coding-string (concat "<?xml etc...") 'utf-8)
instead?
没有什么可以告诉 url 你使用什么编码系统,所以我想你必须自己编码你的数据。这也应该给出正确的Content-length
标题,因为它来自(length url-request-data)
,对于大多数 UTF-8 字符串来说,这显然会给出错误的结果。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)