I am having the following error when I try to use cURL to post a request on my localhost.
The request I am sending:
C:\Program Files (x86)\cURL\bin>curl -v -H "Content-type: application/json" -H "Accept: application/json" -X POST http://localhost:3000/users/sign_in -d '{"user": {"email":"email2@email.com", "password":"1234"}}'
and this is the error I am getting:
* Trying ::1...
* Connected to localhost (::1) port 3000 (#0)
> POST /users/sign_in HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.46.0
> Content-type: application/json
> Accept: application/json
>
< HTTP/1.1 411 Length Required
< Content-Type: text/html; charset=ISO-8859-1
< Server: WEBrick/1.3.1 (Ruby/2.2.4/2015-12-16)
< Date: Thu, 05 May 2016 19:12:52 GMT
< Content-Length: 303
< Connection: close
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD><TITLE>Length Required</TITLE></HEAD>
<BODY>
<H1>Length Required</H1>
WEBrick::HTTPStatus::LengthRequired
<HR>
<ADDRESS>
WEBrick/1.3.1 (Ruby/2.2.4/2015-12-16) at
localhost:3000
</ADDRESS>
</BODY>
</HTML>
* Closing connection 0
The problem is my GET requests work perfectly fine but POST requests are not working.
I tried using escape quotes:
C:\Program Files (x86)\cURL\bin>curl -v -H "Content-type: application/json" -H "Accept: application/json" -X POST http://localhost:3000/users/sign_in -d "{\"user\": \"{\"email\":\"email2@email.com\", \"password\":\"1234\"}\"}"
Beginning of the error:
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying ::1...
* Connected to localhost (::1) port 3000 (#0)
> POST /users/sign_in HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.46.0
> Content-type: application/json
> Accept: application/json
> Content-Length: 7
>
* upload completely sent off: 7 out of 7 bytes
MORE HTML/JAVASCRIPT ERROR
<h2 style="margin-top: 30px">Request</h2>
<p><b>Parameters</b>:</p> <pre>None</pre>
<div class="details">
<div class="summary"><a href="#" onclick="return toggleSessionDump()">Toggle session dump</a></div>
<div id="session_dump" style="display:none"><pre></pre></div>
</div>
<div class="details">
<div class="summary"><a href="#" onclick="return toggleEnvDump()">Toggle env dump</a></div>
<div id="env_dump" style="display:none"><pre>GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "application/json"
REMOTE_ADDR: "::1"
REMOTE_HOST: "::1"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"</pre></div>
</div>
<h2 style="margin-top: 30px">Response</h2>
<p><b>Headers</b>:</p> <pre>None</pre>
</div>
</body>
</html>
* Connection #0 to host localhost left intact
I have been trying to solve the same issue for days now and I hate Windows so much. Any suggestions?