主要是爲我自己的理解,你會怎麼翻譯下面玩具捲曲例如R,使用RCurl或HTTR:翻譯捲曲至R
curl -v -X POST \
https://someurl/endpoint \
-H "Content-Type: application/json" \
-H 'X-Api-Key: abc123' \
-d '{"parameters": [ 1, "foo", "bar" ]}'
我發現這兩種封裝都有點尷尬的超越了簡單的東西GET請求。
我已經試過:
library(httr)
POST("https://someurl/endpoint", authenticate("user", "passwrd"),
body = '{"parameters": [ 1, "foo", "bar" ]}', content_type_json())
得到一個400個狀態。我的捲曲版完美運作。
也試過:
POST("https://someurl/endpoint", add_headers('X-Api-Key: abc123'),
body = '{"parameters": [ 1, "foo", "bar" ]}', content_type_json())
還可以獲得400點的狀態。
我很確定問題在於設置標題。
請問這個問題有幫助嗎? http://stackoverflow.com/questions/5797688/post-request-using-rcurl – 2015-01-20 21:40:13
好吧,首先,我不能在標題的名稱值對中使用破折號。 – 2015-01-20 21:57:05
你試過把身體作爲R列表'body = list(parameters = list(1,「foo」,「bar」))' – sckott 2015-01-20 22:11:50