【问题标题】:415 error when trying to access UMLS API via R vs Postman尝试通过 R 与 Postman 访问 UMLS API 时出现 415 错误
【发布时间】: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 类型正确创建了请求正文?

【问题讨论】:

    标签: r postman httr


    【解决方案1】:

    终于想通了——对于 x-www-form-urlencoded 内容,需要在 POST 调用中包含 encode = 'form'。

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-19
      • 1970-01-01
      • 1970-01-01
      • 2021-09-24
      • 2023-04-11
      相关资源
      最近更新 更多