如何在R中使用CURL -H基本身份验证来访问API

时间:2014-11-20 21:02:29

标签: r curl libcurl

我想从分类器API中检索数据。文档告诉我:

curl -H "Authentication: Basic <my_secret>" "http://www.superapi.io/classifier/test
model_id=123&value=your+text"

如何在R中实现此功能?我尝试使用包RCurl:

getURL("http://www.superapi.io/classifier/test",
userpwd ="secret",
httpheader=list(model_id="123",value="your+text"))

但这没有用:

[1] "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n<title>405 Method Not
Allowed</title>\n<h1>Method Not Allowed</h1>\n<p>The method is not allowed for the requested
URL </p>\n"

1 个答案:

答案 0 :(得分:0)

回答:

getURL("http://wwww.superapi.io/classifier/test?_model_id=123&value=TEST", userpwd="<secret>",
httpauth = 1L)