Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set expected content type #20

Closed
holgersindbaek opened this issue Jul 11, 2013 · 4 comments
Closed

Set expected content type #20

holgersindbaek opened this issue Jul 11, 2013 · 4 comments

Comments

@holgersindbaek
Copy link

I'm trying to verify iTunes receipt with AFMotion (for in-app purchases), but can't set the content type. Keep getting this error:

Expected content type {(\\n    \\\"text/json\\\",\\n    \\\"text/javascript\\\",\\n    \\\"application/json\\\",\\n    \\\"text/html\\\"\\n)}, got text/plain\

Using this code:

encoder = CocoaSecurityEncoder.new
json_data = {"receipt-data" => encoder.base64(receipt), "password" => @shared_secret}
AFJSONRequestOperation.addAcceptableContentTypes(NSSet.setWithObject("text/html"))
AFMotion::JSON.get("https://sandbox.itunes.apple.com/verifyReceipt", q:json_data) do |result|
  ap "BODY: #{result.body}" if result.body
  ap "OBJECT: #{result.object}" if result.object
  ap "ERROR: #{result.error}" if result.error
end

If I use AFNetworking, I can get it to work with:

encoder = CocoaSecurityEncoder.new
json_data = {"receipt-data" => encoder.base64(receipt), "password" => @shared_secret}
baseURL = NSURL.URLWithString("https://sandbox.itunes.apple.com")

client = AFHTTPClient.alloc.initWithBaseURL(baseURL)
client.setDefaultHeader("Accept", value:"application/json")
client.registerHTTPOperationClass(AFJSONRequestOperation.class)
client.setParameterEncoding(AFJSONParameterEncoding)
AFJSONRequestOperation.addAcceptableContentTypes(NSSet.setWithObject("text/plain"))

request = client.requestWithMethod("POST", path:"verifyReceipt", parameters:json_data)
requestOperation = client.HTTPRequestOperationWithRequest(request, success: lambda { |operation, responseObject| 
  ap "operation: #{operation}"
  ap "responseObject: #{responseObject}"
}, failure: lambda {|operation, error|
  ap "operation: #{operation}"
  ap "error: #{error}"
})

But it looks so clumsy, compared to the above code.

Is there any way I can set the expected content type for the original code in AFMotion?

@clayallsopp
Copy link
Collaborator

Is it a copypaste mistake that you're using text/html in your example code, while iTunes is returning text/plain?

@holgersindbaek
Copy link
Author

The "Expected content type..." is copy/paste of the actual error message I got.

Not much to do about what iTunes is returning. All I need to do is to accept that format somehow.

@clayallsopp
Copy link
Collaborator

No like in your "Using this code:" block you posted above, you did:

AFJSONRequestOperation.addAcceptableContentTypes(NSSet.setWithObject("text/html"))

when it should be:

AFJSONRequestOperation.addAcceptableContentTypes(NSSet.setWithObject("text/plain"))

@holgersindbaek
Copy link
Author

Arh... of course. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants