ruby-on-rails - 使用 HTTParty 将时间转换为可消化的 JSON 字符串
问题描述
以下字符串返回结果
@result = HTTParty.post(
'https://test.co.uk/search',
:body => '{ "requestAuditInfo": { "agentCode": "MLG001",
"requestDateTime": "2018-07-29T07:03:38Z" [...]
然而
@result = HTTParty.post(
'https://test.co.uk/search',
:body => '{ "requestAuditInfo": { "agentCode": "MLG001",
"requestDateTime": Time.now.utc.iso8601 [...]
返回零
Time.now.utc.iso8601
返回 控制台,"2018-07-29T07:03:38Z"
这是成功调用所需的字符串。
我怎么了?
更新
:body => "{ 'requestAuditInfo': { 'agentCode': 'MLG001',
'requestDateTime': '2018-07-29T07:03:38Z'
没有被接收 API 消化,返回 NIL 结果
解决方案
您正在发送字符串 "requestDateTime": Time.now.utc.iso8601 [...]" 作为参数。如果要将 rubyTime.now
作为字符串的一部分传递,则需要对其进行插值,如下所示:
"requestDateTime": #{Time.now.utc.iso8601}"
推荐阅读
- javascript - Cannot Delete Fields with Period in Key Name
- android-studio - Flutter not installing properly for Android Studio
- typescript - 值可以是函数或空时的打字稿错误
- r - 在 Shiny 中按列名过滤雷达图
- php - Mailchimp API send campaign
- r - different results between the paper and my code to calculate the p-value of Kolmogorov–Smirnov (K–S) test in R
- wordpress - Hide specific admin color scheme options without CSS?
- java - Only first test in class failed when running multiple classes
- c# - How can I get as much as close to 0 on float?
- gnuplot - 在 Gnuplot 中使用调色板进行绘图时,将低于某个截止点的点的颜色设置为灰色