[当前正在使用Ruby进行对API的POST调用,这是我进行POST的方法的代码:
def ccUpdate
@result = HTTParty.post("#{apiUrl}"),
body => "#{apiUrlEnd}",
headers => {'ver' => 1,'src_sys_type' => 2,'src_sys_name' => 'automation'},
command1 => {
'cmd' => 'redacted',
'ref' => 'redacted',
}.to_json
end
[每当我尝试运行代码时,都会在第3行收到此错误:
syntax error, unexpected =>, expecting keyword_end
body => "#{apiUrlEnd}",
^~
syntax error, unexpected ',', expecting keyword_end
body => "#{apiUrlEnd}",
有人能解释为什么会这样吗?试图弄清楚它有点令人沮丧:(
尝试:
def ccUpdate
@result = HTTParty.post(
"#{apiUrl}",
body => "#{apiUrlEnd}",
headers => {'ver' => 1,'src_sys_type' => 2,'src_sys_name' => 'automation'},
command1 => {
'cmd' => 'redacted',
'ref' => 'redacted',
}.to_json
)
end
关于解释,HTTParty.post的参数应该在下面,但是您在同一行上加了一个大括号。红宝石将所有后续代码解释为不在参数范围内,并且在语法上不正确。