简体   繁体   English

带导轨的Windows上带有cURL的POST请求中的错误

[英]error in POST request with cURL on windows with rails

I am having the following error when I try to use cURL to post a request on my localhost. 当我尝试使用cURL在本地主机上发布请求时出现以下错误。

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. 问题是我的GET请求工作得很好,但POST请求却不起作用。

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 更多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: &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. 几天来,我一直在尝试解决相同的问题,我非常讨厌Windows。 Any suggestions? 有什么建议么?

如对这个问题的答案的注释中所建议,请尝试避免使用单引号,而应避免使用其他引号,例如: -d "{\\"user\\": \\"....\\"}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM