【发布时间】:2018-01-25 07:21:54
【问题描述】:
所以我看到了一些关于使用 httr 的 GET 和 POST 请求的帖子,但我试图弄清楚如何更新我公司数据库中的值,并试图弄清楚如何使用这些函数。特别是,我正在为如何格式化 body 参数而苦苦挣扎。例如,浏览一下我的数据库:
library("httr")
# I can do a post request to grab data from the companys db (they told me to use POST instead of GET)
my_request <- httr::POST("https://mycompany.com/ourdb/data/userInfo/",
body = '{}',
httr::add_headers(
'X-login-Key' = '12345678',
'OS-Version' = 'iOS 10.3.1',
'User-Agent' = 'company/1.2.3.456',
'Content-Type' = 'application/json',
'X-Access-Token' = 'dkdfjueek12384kdndcos/da8L9u0=',
'Nonce' = '1',
'Accept' = 'application/json'),
), encode = "json")
http_status(my_request)$category
[1] "Success"
mycontent = content(my_request)
names(mycontent)
[1] "nonce" "templateJson" "settingsJson" "plusButtonTree" "templateVersion"
mycontent$settingsJson$user_gender
[1] 1
我想将数据库中的 user_gender 值从 1 更改为 2(或任何其他数字)。我想我必须使用 body 参数来执行此操作,但我不确定如何执行此操作。我也不确定我是否应该为此使用 PUT 或 PATCH 动词/函数。
提前感谢您的帮助!
【问题讨论】: