문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top