问题
I am trying to structure a POST json request using httr. The API documentation proposes the following the CURL request:
curl -X POST -H "Authorization:Token XXXXXXXXX" -H "Content-Type: application/json" --data "{\"texts\":[\"A simple string\"]}" https://api.uclassify.com/v1/uclassify/topics/classify
My R httr implementation is the following:
POST("https://api.uclassify.com/v1/uClassify/Topics/classify",
encode="json",
add_headers('Authorization:Token'="XXXXXXXXX"),
body=("A simple string"))
But I received a 401 error message which indicates that my authentication failed. Any suggestion on how I can implement the CURL request on httr?
回答1:
Just in case it can help somebody else, the below code works for me:
POST("https://api.uclassify.com/v1/uClassify/Topics/classify",
encode="json",
add_headers(Authorization = "Token XXXXXXXXX"),
body = "{\"texts\":[\"A simple string\"]}")
来源:https://stackoverflow.com/questions/41809707/httr-post-authentication-error