当我尝试使用cURL在我的localhost上发布请求时出现以下错误。
我发送的请求:
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"}}'
这是我得到的错误:
* 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
问题是我的GET请求工作得很好,但POST请求无效。
我尝试使用转义引号:
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\"}\"}"
错误开始:
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
更多HTML / JAVASCRIPT错误
<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
我几天来一直试图解决同样的问题而且我非常讨厌Windows。有什么建议吗?