在emacs中使用url elisp包创建POST:utf-8问题 [英] Creating a POST with url elisp package in emacs: utf-8 problem
问题描述
我目前正在创建一个休息客户端,用于以pastie.el的精神制作博客帖子。主要目标是让我在emacs上编写一个纺织品,并发贴到一个可以创建它的Rails应用程序中。它工作正常,直到我输入任何西班牙语或日语,然后我得到一个500错误。 pastie.el也有同样的问题。
I'm currently creating a Rest client for making blog posts much in the spirit of pastie.el. The main objective is for me to write a textile in emacs and make a post to a Rails application that will create it. It is working fine until I type anything in either spanish or japanese, then I get a 500 error. pastie.el has this same problem also by the way.
这是代码:
(require'url)
(require 'url)
(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字符,使ñ成为&#241(这样做)。
The only way I can imagine right now that the problem could be fixed is by making emacs encode the utf-8 characters so that a 'ñ' becomes 'ñ' (which works by the way).
这个问题可以解决什么问题?
What could be a work around for this problem?
编辑:'*'不等于*'。我的意思是,如果我使用emacs编码为utf-8,例如'sgml-char',它将使整个帖子变为utf-8编码。喜欢*从而使RedCloth无法将其转换成html。对不起,这是非常糟糕的解释。
'*' is not equivalent to *'. What I meant was that if I encoded to utf-8 with emacs using for example 'sgml-char' it would make the whole post become utf-8 encoded. Like *Textile bold* thus making RedCloth being unable to convert it into html. Sorry, it was very bad explained.
推荐答案
猜测:如果您设置 url-请求数据
到
(encode-coding-string (concat "<?xml etc...") 'utf-8)
而不是
没有什么真的可以告诉你什么编码系统你使用,所以我想你必须自己编码你的数据。这也应该给出一个正确的 Content-length
头,因为它刚刚来自(length url-request-data)
,这显然会给大多数UTF-8字符串带来错误的结果。
There's nothing really to tell url what coding system you use, so I guess you have to encode your data yourself. This should also give a correct Content-length
header, as that just comes from (length url-request-data)
, which would obviously give the wrong result for most UTF-8 strings.
这篇关于在emacs中使用url elisp包创建POST:utf-8问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!