简体   繁体   English

使用httparty发送json对象

[英]send json object with httparty

I'm trying to implement the in App purchase from within my iPhone app. 我正在尝试从我的iPhone应用程序中实现应用内购买。 To verify the receipt I need to send a json object to the iTunes server. 要验证收据,我需要将json对象发送到iTunes服务器。 Im trying to do this with the httparty plugin: 我试图用httparty插件做到这一点:

require 'httparty'

class ItunesVerification
  include HTTParty
  base_uri 'https://sandbox.itunes.apple.com'
  default_params :output => 'json'
  format :json
end


@result = ItunesVerification.post('/verifyReceipt', :query => {'receipt-data' => params[:receipt]})

When I do so, I keep getting a... 当我这样做的时候,我一直在......

{"status":21002, "exception":"java.lang.NullPointerException"} {“status”:21002,“exception”:“java.lang.NullPointerException”}

... error. ......错误 I guess this is because of the not right implementation of the json object. 我想这是因为json对象的执行不正确。 The Object should have the structure: { "receipt-data" : "...." }... because of the - character in receipt-data it dosn't accept as :receipt-data identifyer... 对象应该具有以下结构:{“receipt-data”:“....”} ...因为收据数据中的 - 字符它不能接受为:收据 - 数据识别器......

How do I have to implement that right? 我该如何实现这一权利?

Thanks Maechi 谢谢Maechi

I got the solution: 我得到了解决方案:

I have to write :body instead of :query! 我要写:身体而不是:查询! Then it gets sent as a json object! 然后它作为json对象发送!

Markus 马库斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM