How to make a POST request with header and data options in R using httr::POST?

后端 未结 1 1101
情话喂你
情话喂你 2020-12-22 08:09

I am trying make a POST request with data and header information using httr::POST. I can see how to make a POST request, but I am unable to get it to work with

相关标签:
1条回答
  • 2020-12-22 08:52

    You could try this; with content type and headers added:

    link <- "http://www.my-api.com"
    df <- list(name="Fred", age="5")
    
    httr::POST(url = link,
               body =  jsonlite::toJSON(df, pretty = T, auto_unbox = T),
               httr::add_headers(`accept` = 'application/json'), 
               httr::content_type('application/json'))
    
    0 讨论(0)
提交回复
热议问题