0

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: &quot;CGI/1.1&quot;
HTTP_ACCEPT: &quot;application/json&quot;
REMOTE_ADDR: &quot;::1&quot;
REMOTE_HOST: &quot;::1&quot;
SERVER_NAME: &quot;localhost&quot;
SERVER_PROTOCOL: &quot;HTTP/1.1&quot;</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?

1 Answers1

0

As suggested in a comment to an answer in this question, try avoid using single quote-marks and instead escaping the others like this: -d "{\"user\": \"....\"}"

Community
  • 1
  • 1
ollpu
  • 1,783
  • 15
  • 26
  • Ooh, according the the curl-manual, the URL should be at the end of the parameters, not in the middle. Try that with the escaping. – ollpu May 05 '16 at 19:37
  • Thanks for your answers, tried that as well, same error –  May 05 '16 at 19:41
  • That blob you pasted looks like the tail of a Rails error-message. The earlier parts might be indicating some other error. (That's not nice of Rails to just spit you an HTML-error message when you were asking for JSON) – ollpu May 05 '16 at 19:46
  • just added the beginning of the error. Not much to see there either –  May 05 '16 at 21:17
  • The very beginning is just the things curl is printing. Can you paste the whole thing with something like pastebin? – ollpu May 05 '16 at 21:19