本文介绍了httr POST 身份验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 httr 构建 POST json 请求.API 文档提出了以下 CURL 请求:

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

我的 R httr 实现如下:

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"))

但我收到了 401 错误消息,表明我的身份验证失败.关于如何在 httr 上实现 CURL 请求的任何建议?

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?

推荐答案

以防万一它可以帮助别人,下面的代码对我有用:POST("https://api.uclassify.com/v1/uClassify/Topics/classify",编码=json",add_headers(Authorization = "Token XXXXXXXXX"),body = "{\"texts\":[\"一个简单的字符串\"]}")

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\"]}")

这篇关于httr POST 身份验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 10:39