title: How to send POST request from Android app to Rails application?
body: <p>I have problem with sending POST request to my rails application from Android app (using Spring for Android)</p>
  
  <p>I have following Rails controller:</p>
  
  <pre><code>  # POST /users
    # POST /users.json
  
    def create
  @user = User.new(user_params)
  
  respond_to do |format|
    if @user.save
      format.html { redirect_to @user, notice: 'User was successfully created.' }
      format.json { render action: 'show', status: :created, location: @user }
    else
      format.html { render action: 'new' }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
    end
  # Never trust parameters from the scary internet, only allow the white list through.
  def user_params
    params.require(:user).permit(:name, :email)
  end
  </code></pre>
  
  <p>I'm sending POST request (using Spring for Android):</p>
  
  <pre><code>        RestTemplate restTemplatePost = new RestTemplate();
          restTemplatePost.getMessageConverters().add(new StringHttpMessageConverter());
  
  
          UserDto user = new UserDto();
          user.name = "testName";
          user.email = "test@fromandroid.com";
  
          Gson gson = new Gson();
          String request = gson.toJson(user);
          restTemplatePost.postForObject(createUserUrl, request, String.class);
          } catch(RestClientException e) {
              Log.e("POST",e.getLocalizedMessage());
          }
  </code></pre>
  
  <p>value of String request is {"email":"test@fromandroid.com","name":"testName"}</p>
  
  <p>and createUserUrl has value of: <code>http://10.0.0.2:3000/users</code></p>
  
  <p>however, I still get the following error:</p>
  
  <pre><code>&gt; W/RestTemplate(3299): POST request for "http://10.0.0.2:3000/users"
  &gt; resulted in 400 (Bad Request); invoking error handler
  </code></pre>
  
  <p>I'm able to send the GET request, but POST doesn't work. What am I doing wrong? 
  I used CURL to get better error message and it returns: </p>
  
  <pre><code>param not found: user 
  </code></pre>
  
  <p>so the problem might be with required user and optional name and emails parameters which are accepted by REST API, but how should I format user in json for it to work?</p>
  
  <p>I'd greatly appreciate your help!</p>