我正在努力写一个httr:POST语句,等同于下面的curl命令(实际的client_id & client_secret替换为伪字符串):
curl -i -X POST -H "ContentType: x-www-form-urlencoded" -d
"grant_type=client_credentials&client_id=XXXXXXXX&client_secret=XXXXXXXX"
"https://api.beta.tab.com.au/oauth/token"我尝试了以下方法,但似乎不起作用:
POST("https://api.beta.tab.com.au/oauth/token",
add_headers('Content-Type'='application/json'),
body = list(grant_type = "client_credentials",
client_id = "XXXXXXXX",
client_secret = "XXXXXXXX"),
encode = "json")我希望得到的状态码是200,但事实并非如此……
发布于 2019-08-21 13:29:04
我假设你上面的curl命令是有效的。检查curl -d应用程序的定义时,可以看到数据是使用内容类型应用程序/x-www- here -urlencoded传递给服务器的。但是,您正在使用json编码构建post命令。换句话说,你没有在你的帖子正文中发送相同的格式,我假设这是你的问题,因为你的服务器可能希望数据是形式的are编码的,而不是json。您应该选中此quickstart,并尝试在设置了详细标志的交互式会话中运行命令,以查看发送到服务器的内容。
https://stackoverflow.com/questions/57584091
复制相似问题