[英]HTTParty Post Some parts JSON encoded, some not
I am trying to send a post request to a separate app where I need to send a matching signature that is not json encoded and the data, which is json encoded. 我试图将发布请求发送到单独的应用程序,在该应用程序中,我需要发送不经过json编码的匹配签名和经过json编码的数据。 I keep getting errors when I try to do this, so I'm just not understanding how to format it, and I can't find any examples on SO or their documentation (or anywhere else on the web). 当我尝试这样做时,我总是收到错误消息,所以我只是不了解如何格式化它,因此我无法在SO或其文档(或网络上的任何其他地方)上找到任何示例。
signature = create_signature
result = HTTParty.post("weburl.com/file/to/post_to.php",
:body => {[ signature,
:data => { :timestamp => @message.created_at,
:url => company.request_host,
:name => @message.name,
:email => @message.email,
:phone => @message.phone,
:product => @message.service,
:comments => @message.message
}.to_json
]},
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
:verify => false )
The error I'm getting currently is syntax error, unexpected '}', expecting => ]}, ^ 我当前遇到的错误是语法错误,意外的'}',期望=>]},^
I've also tried without the arrays, without the data array, etc. 我也试过没有数组,没有数据数组,等等。
How do I format this to properly submit this info? 如何格式化此格式以正确提交此信息?
I think you need to move your .to_json to the end of the object. 我认为您需要将.to_json移动到对象的末尾。
:body => {[ signature,
:data => { :timestamp => @message.created_at,
:url => company.request_host,
:name => @message.name,
:email => @message.email,
:phone => @message.phone,
:product => @message.service,
:comments => @message.message
}
].to_json},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.