【发布时间】:2021-05-29 23:34:04
【问题描述】:
我可以通过 Postman 成功点击端点进行 UMLS 身份验证,但是在将此代码移动到 R 并使用 httr 时不断收到 415 错误。这似乎只在使用 x-www-form-urlencoded(而不是 json)时有效。
我的相关邮递员标题是: 内容类型:application/x-www-form-urlencoded 和 接受:/*/
并尝试在 R 中重新创建它:
library(httr)
auth_endpoint <- "https://utslogin.nlm.nih.gov/cas/v1/api-key"
auth_headers <- c("Content-Type" = "application/x-www-form-urlencoded",
"Accept" = "*/*")
getTGT <- function(endpoint, headers) {
request_body <- list(apikey = "API_KEY_HERE")
request <- POST(url = endpoint,
headers = add_headers(.headers = headers),
body = request_body
}
此请求返回 415 错误,我只能说它与 Content-Type 有关。我更习惯于使用 JSON,但这在 Postman 中也不起作用。我是否为 x-www-form-urlencoded 类型正确创建了请求正文?
【问题讨论】: