我正在照着如下这段范例代码模拟 POST 提交表单数据,遇到了中文字符的问题,一到含有中文字符的那行就会被提示 C:\Users\tylr\Desktop>ruby auto_post.rb auto_post.rb:11: invalid multibyte char (UTF-8) auto_post.rb:11: invalid multibyte char (UTF-8) auto_post.rb:11: syntax error, unexpected $end, expecting '}' "ctl00" => "测试",
我尝试了在脚本行首加入#encoding:utf-8,但也没有帮助,还望得到大家指点,谢谢先!
范例代码: require "uri" require "net/http"
params = {'box1′ => 'Nothing is less important than which fork you use. Etiquette is the science of living. It embraces everything. It is ethics. It is honor. -Emily Post', 'button1′ => 'Submit' } x = Net::HTTP.post_form(URI.parse('http://www.interlacken.com/webdbdev/ch05/formpost.asp'), params)