0
  # POST /players
  # POST /players.json
  def create
    #  player.create(params[:player])
    @player = Player.new(player_params)

    respond_to do |format|
      if @player.save
        format.html { redirect_to @player, notice: 'Player was successfully created.' }
        format.json { render :show, status: :created, location: @player }
      else
        format.html { render :new }
        format.json { render json: @player.errors, status: :unprocessable_entity }
      end
    end
  end

My player just have One data name.I think i can post a json data to /tickets.json to create a new model.Is it right? So how to do it?

POST http://www.address.com/tickets.json HTTP/1.1 
Content-Type: application/json;charset=utf-8

{"name":"test"}

Is it right code in http protocol?

Sorry for my English.

I use arduino mkr1000 to post json this is my arduino code:

    client.println("POST  http://192.168.1.11:3000/players.json HTTP/1.1");
    client.println("Content-Type: application/json");
    client.println("Accept: application/json");
    client.println("{\"name\":\"test\"}");

And rails server return :

2016-08-01 16:56:14 +0800: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
2016-08-01 16:56:14 +0800: ENV: {"rack.version"=>[1, 3], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"puma 3.6.0 Sleepy Sunday Serenity", "GATEWAY_INTERFACE"=>"CGI/1.2", "REQUEST_METHOD"=>"POST"}
---
zix
  • 17
  • 4
  • What you did is perfectly alright. Go on. –  Aug 01 '16 at 07:28
  • I try.but response HTTP/1.1 400 Bad Request. – zix Aug 01 '16 at 08:09
  • Could you add the log of the web server after you made a request? – Tobias Aug 01 '16 at 08:28
  • 2016-08-01 16:56:14 +0800: HTTP parse error, malformed request (): # 2016-08-01 16:56:14 +0800: ENV: {"rack.version"=>[1, 3], "rack.errors"=>#>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"puma 3.6.0 Sleepy Sunday Serenity", "GATEWAY_INTERFACE"=>"CGI/1.2", "REQUEST_METHOD"=>"POST"} --- – zix Aug 01 '16 at 08:57
  • I think [this post](http://stackoverflow.com/questions/3677400/making-a-http-post-request-using-arduino) can help you – Carlos Oliveira Aug 01 '16 at 17:10

0 Answers0