How to send POST request from Android app to Rails application?

I have problem with sending POST request to my rails application from Android app (using Spring for Android)

I have following Rails controller:

  # POST /users
  # POST /users.json

  def create
@user =

respond_to do |format|
    format.html { redirect_to @user, notice: 'User was successfully created.' }
    format.json { render action: 'show', status: :created, location: @user }
    format.html { render action: 'new' }
    format.json { render json: @user.errors, status: :unprocessable_entity }
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
  params.require(:user).permit(:name, :email)

I'm sending POST request (using Spring for Android):

        RestTemplate restTemplatePost = new RestTemplate();
        restTemplatePost.getMessageConverters().add(new StringHttpMessageConverter());

        UserDto user = new UserDto(); = "testName"; = "";

        Gson gson = new Gson();
        String request = gson.toJson(user);
        restTemplatePost.postForObject(createUserUrl, request, String.class);
        } catch(RestClientException e) {

value of String request is {"email":"","name":"testName"}

and createUserUrl has value of:

however, I still get the following error:

> W/RestTemplate(3299): POST request for ""
> resulted in 400 (Bad Request); invoking error handler

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:

param not found: user 

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?

I'd greatly appreciate your help!


Please ensure that your controller config accept POST method, may be it just receives GET.



And you can use RestClient (Plugin of Firefox or Chrome) to test your api.

Rest Client - Firefox

Rest Client - Chrome

There are some issues you must have to follow to post.

  1. you need to post data something like:

    {"user_params" : {"email":"","name":"testName"}}

    to create a user (according to your controller).

  2. To post data add Request Header. As you sending json data, so header will be Content-Type: application/json.

Also I'm suggesting you to use a FireFox addons is named "RESTClient" to simulate this scenario.


Need Your Help

How i could make a jess rule in java

java jess

I am a begginer at jess rules so i can't understand how i could use it. I had read a lot of tutorials but i am confused.

Carrierwave file uploading and resizing being interrupted

ruby-on-rails-3.2 carrierwave minimagick

I've run the process to overcome the known issue of ruby 1.9 and ImageMagick.