In [4]: urllib.urlencode({"name":"汉字".decode('utf-8').encode('GB2312'),"id":u"12345"})
Out[4]: 'name=%BA%BA%D7%D6&id=12345'
根据 curl 手册页,
--data-urlencode <data>
...
The <data> part can be passed to
curl using one of the following syntaxes:
...
name=content
This will make curl URL-encode the content part and pass that on.
Note that the name part is expected to be URL-encoded already.
由于 curl 将对内容进行 URL 编码,因此我们需要向它传递一个尚未进行 URL 编码的字符串:
In [7]: urllib.unquote(urllib.urlencode({"name":"汉字".decode('utf-8').encode('GB2312'),"id":u"12345"}))
Out[7]: 'name=\xba\xba\xd7\xd6&id=12345'
因此,尝试
url="http://xxx.com/login.asp"
curl --data-urlencode 'name=\xba\xba\xd7\xd6&id=12345' $url