需要帮助以Rails 5

时间:2018-12-25 11:18:43

标签: ruby-on-rails json api http-post httparty

我有这个json负载,我正在尝试使用HTTParty发送到rails中的第三方API。但是,在“ orderCustomer”对象结束后,它将停止读取json。当我使用邮递员将其直接发送到终点时,此json结构有效。 我的rails代码:

order = HTTParty.post('url', :basic_auth => auth, :header => {'Content-Type' => 'application/json' }, :body => @order_cust)

@order_cust是有效负载,如下所示。有人知道为什么有效载荷会停止吗?是因为数组?我需要将有效载荷分成几部分吗?即有一个部分保存orderCusotmer数据和items数据,然后将它们串在一起?我很困,所以任何建议或建议都会有所帮助!

{
  "orderCustomer": {
      "firstName": "John",
      "lastName": "Doe",
      "companyName": "ACME",
      "address1": "1 Acme Way",
      "address2": "",
      "city": "Livingston",
      "state": "MT",
      "postalCode": "59047",
      "countryCode": "US",
      "email": "jdoe@acme.com",
      "phone": "1234567890"
  },
  "items": [
      {
          "itemSequenceNumber": 1,
          "productID": 9876,
          "quantity": 1,
          "itemFile": "http://www.yourdomain.com/files/printReadyArtwork1.pdf"
      }
  ],
  "shipments": [
      {
          "shipmentSequenceNumber": 1,
          "firstName": "John",
          "lastName": "Doe",
          "companyName": "ACME",
          "address1": "1 Acme Way",
          "address2": "",
          "city": "Livingston",
          "state": "MT",
          "postalCode": "59047",
          "countryCode": "US",
          "phone": "1234567890",
          "shippingMethod": "FDXG"
      }
  ]
}

但是,当我通过邮递员将此数据发布到邮递员中时,它可以正常工作,当我通过导轨将其发送时,它卡在了项目和装运部分,并说找不到该数据。关于如何使用HTTParty完全传递此数据的任何建议都会很棒。我尝试添加to_json,而我正在使用的API并非如此。

0 个答案:

没有答案