httr POST authentication error

一笑奈何 提交于 2021-02-11 08:58:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!