在Windows上使用cURL的POST请求中出错

时间:2016-05-02 16:40:47

标签: ruby-on-rails windows post curl

我正在尝试使用Windows 10上的cURL向我的localhost发送POST请求。我正在使用Ruby on Rails,我的数据库是PostgresQL。我尝试了所有在各处发布的解决方案,但没有一个正在发挥作用。

这就是cURL中的一个类型:

curl -v -g -H "Accept: application/json" -H "Content-type: application/json" -H "Authorization: NVNNymcrAExBdDsaje9z" -X POST http://localhost:3000/users/reservations -d '{"reservation": {"venue":"new Venue", "venue_id":"1", "reservation_date":"2016/04/26", "num_people":"3", "num_bottles":"1"}}'

这是我得到的错误:

    Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying ::1...
*   Trying 127.0.0.1...
* connect to ::1 port 3000 failed: Connection refused
* connect to 127.0.0.1 port 3000 failed: Connection refused
* Failed to connect to localhost port 3000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 3000: Connection refused
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: {venue:new Venue,/
* Could not resolve host: {venue
* Closing connection 1
curl: (6) Could not resolve host: {venue
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: venue_id:1,/
* Could not resolve host: venue_id
* Closing connection 2
curl: (6) Could not resolve host: venue_id
Note: Unnecessary use of -X or --request, POST is already inferred.
* Could not resolve host: reservation_date
* Closing connection 3
curl: (6) Could not resolve host: reservation_date
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: num_people:3,/
* Could not resolve host: num_people
* Closing connection 4
curl: (6) Could not resolve host: num_people
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: num_bottles:1}}'/
* Could not resolve host: num_bottles
* Closing connection 5
curl: (6) Could not resolve host: num_bottles

我尝试使用这样的转义引号:

curl -v -g -H "Accept: application/json" -H "Content-type: application/json" -H "Authorization: NVNNymcrAExBdDsaje9z" -X POST http://localhost:3000/users/reservations/ -d {\"reservation\": {\"venue\":\"new Venue\", \"venue_id\":\"1\", \"reservation_date\":\"2016/04/26\", \"num_people\":\"3\", \"num_bottles\":\"1\"}}

这是我使用转义引号得到的错误:

    Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying ::1...
*   Trying 127.0.0.1...
* connect to ::1 port 3000 failed: Connection refused
* connect to 127.0.0.1 port 3000 failed: Connection refused
* Failed to connect to localhost port 3000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 3000: Connection refused
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: {"venue":"new/
* Could not resolve host: {"venue"
* Closing connection 1
curl: (6) Could not resolve host: {"venue"
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: Venue",/
* Could not resolve host: Venue",
* Closing connection 2
curl: (6) Could not resolve host: Venue",
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: "venue_id":"1",/
* Could not resolve host: "venue_id"
* Closing connection 3
curl: (6) Could not resolve host: "venue_id"
Note: Unnecessary use of -X or --request, POST is already inferred.
* Could not resolve host: "reservation_date"
* Closing connection 4
curl: (6) Could not resolve host: "reservation_date"
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: "num_people":"3",/
* Could not resolve host: "num_people"
* Closing connection 5
curl: (6) Could not resolve host: "num_people"
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: "num_bottles":"1"}}/
* Could not resolve host: "num_bottles"
* Closing connection 6
curl: (6) Could not resolve host: "num_bottles"

我也尝试在curl / bin中移动我的数据文件并使用-d @ text.txt,如下所示:

curl -v -g -H "Accept: application/json" -H "Content-type: application/json" -H "Authorization: NVNNymcrAExBdDsaje9z" -X POST http://localhost:3000/users/reservations -d @text.txt

这是错误:

    Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying ::1...
*   Trying 127.0.0.1...
* connect to ::1 port 3000 failed: Connection refused
* connect to 127.0.0.1 port 3000 failed: Connection refused
* Failed to connect to localhost port 3000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 3000: Connection refused

我愿意接受任何建议吗?您认为我的问题是什么?如何解决此问题并发出正确的POST请求?

0 个答案:

没有答案