Issue with an authenicated POST to Rails using curl
<p>I'm looking to POST to a Rails app from curl. I have been able to authenticate and get a 200 response. But when I attempt to POST some data it fails.</p>

<p>My controller code:</p>

<pre><code>class TestApiController &lt; ApplicationController
   before_action :authenticate

  def server_reporter
   puts params
  end

   protected
   def authenticate
     authenticate_or_request_with_http_token do |token, options|
       # User.find_by(auth_token: token)
        token == '1234'
     end
   end
end
</code></pre>

<p>when I run this </p>

<p><code>curl -v localhost:3000/test_api/server_reporter  -IH "Authorization: Token token=1234"</code></p>

<p>I get</p>

<pre><code>Started HEAD "/test_api/server_reporter" for ::1 at 2016-10-10 11:27:19 +0200
Processing by TestApiController#server_reporter as */*
{"controller"=&gt;"test_api", "action"=&gt;"server_reporter"}
  Rendered test_api/server_reporter.html.erb within layouts/application (0.2ms)
Completed 200 OK in 221ms (Views: 220.2ms | ActiveRecord: 0.0ms)```
</code></pre>

<p>when I try</p>

<pre><code>curl -v localhost:3000/test_api/server_reporter -X POST  -H "Authorization: Token token=1234"   -H "Content-Type: application/json" -d '{"server": {"name": "Asterix"}}' 
</code></pre>

<p>I get the following in the Rails console.</p>

<pre><code>Started POST "/test_api/server_reporter" for ::1 at 2016-10-10 15:59:36 +0200
Processing by TestApiController#server_reporter as */*
  Parameters: {"server"=&gt;{"name"=&gt;"Asterix"}, "test_api"=&gt;{"server"=&gt;{"name"=&gt;"Asterix"}}}
Can't verify CSRF token authenticity
Completed 422 Unprocessable Entity in 1ms (ActiveRecord: 0.0ms)

ActionController::InvalidAuthenticityToken - ActionController::InvalidAuthenticityToken:
</code></pre>

<p>Edit: adding the <code>curl</code> response.</p>

<pre><code>$ curl -v localhost:3000/test_api/server_reporter -X POST  -H "Authorization: Token token=1234"   -H "Content-Type: application/json" -d '{"server": {"name": "Asterix"}}' 
*   Trying ::1...
* Connected to localhost (::1) port 3000 (#0)
&gt; POST /test_api/server_reporter HTTP/1.1
&gt; Host: localhost:3000
&gt; User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
&gt; Accept: */*
&gt; Referer: 
&gt; Authorization: Token token=1234
&gt; Content-Type: application/json
&gt; Content-Length: 31
&gt; 
* upload completely sent off: 31 out of 31 bytes
&lt; HTTP/1.1 422 Unprocessable Entity
&lt; Content-Type: text/plain; charset=utf-8
&lt; X-Meta-Request-Version: 0.4.0
&lt; X-Request-Id: a13faa8e-20b4-4107-ba5f-1c6fde1f8ce1
&lt; X-Runtime: 0.077414
&lt; Set-Cookie: __profilin=p%3Dt; path=/
&lt; Connection: close
&lt; Server: thin
&lt; 
ActionController::InvalidAuthenticityToken at /test_api/server_reporter
=======================================================================

&gt; ActionController::InvalidAuthenticityToken
</code></pre>