2015-04-01 110 views
0

我無法發送經由捲曲的POST請求:張貼與CURL到API

捲曲-H 「內容類型:應用/ JSON」 -X POST -d「{ 「用戶名」:「測試@ test.com「,」password「:」testpassword「,」verify「:」testpassword「,first_name =」Mo「,last_name =」Lester「}'http://stuff.com/signup

我收到的錯誤信息表示服務器isn沒有得到密碼,可能根本沒有數據。

我嘗試在URL周圍發表引號,但運氣不佳。

新來cURL,原諒我的無知。

回答

1

你忘了周圍的first_namelast_name元素的報價,你已經包含在這些任務,而不是JSON :字符導致無效JSON的另一端將無法解析=。這是一個更正的有效JSON請求:

curl -H "Content-Type: application/json" -X POST -d '{"username":"[email protected]", "password":"testpassword", "verify":"testpassword", "first_name": "Mo", "last_name": "Lester"}' http://stuff.com/signup 
+0

咖啡太多,睡眠不足。感謝您指出我的錯誤。 – 2015-04-01 21:58:40

+0

今天我試了一下代碼。它仍然是行爲像變量不會使api ... curl -H「Content-Type:application/json」-X POST -d'{「username」:「[email protected]」 ,「password」:「testpassword」,「verify」:「testpassword」,「first_name」:「Mo」,「last_name」:「Lester」}'http://stuff.com/signup 返回Nonetype錯誤我的第一條路線。如果您需要,我可以用代碼更新問題。 – 2015-04-02 17:19:48

+0

該API的文檔在哪裏? – 2015-04-02 17:22:23