Question

AFMotion says

The request_parameters is a hash containing your parameters to attach as the request body or URL parameters, depending on request type.

However, I can't figure out how to send a JSON request as a Body payload.

client.post("users", name: "@clayallsopp", library: "AFMotion") do |result|
  ...
end

This example from their page sends Content-Type as application/x-www-form-urlencoded; charset=utf-8, however, my api requires the MIME type to be application/json

Was it helpful?

Solution

You can set the request_serializer and response_serializer both to :json to properly send/receive JSON:

@client = AFMotion::Client.build("https://alpha-api.app.net/") do
  request_serializer :json
  response_serializer :json
end

AFNetworking will then use the AFJSONRequestSerializer which will set the Content-Type header to application/json.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top