POST file to a server.
POST( url = NULL, config = list(), ..., body = NULL, encode = c("multipart", "form", "json", "raw"), handle = NULL )
url | the url of the page to retrieve |
---|---|
config | Additional configuration settings such as http
authentication ( |
... | Further named parameters, such as |
body | One of the following:
|
encode | If the body is a named list, how should it be encoded? Can be one of form (application/x-www-form-urlencoded), multipart, (multipart/form-data), or json (application/json). For "multipart", list elements can be strings or objects created by
|
handle | The handle to use with this request. If not
supplied, will be retrieved and reused from the |
A response()
object.
b2 <- "http://httpbin.org/post" POST(b2, body = "A simple text string")#> Response [http://httpbin.org/post] #> Date: 2020-08-17 22:22 #> Status: 200 #> Content-Type: application/json #> Size: 479 B #> { #> "args": {}, #> "data": "A simple text string", #> "files": {}, #> "form": {}, #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Content-Length": "20", #> "Host": "httpbin.org", #> ...#> Response [http://httpbin.org/post] #> Date: 2020-08-17 22:22 #> Status: 200 #> Content-Type: application/json #> Size: 590 B #> { #> "args": {}, #> "data": "", #> "files": {}, #> "form": { #> "x": "A simple text string" #> }, #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> ...#> Response [http://httpbin.org/post] #> Date: 2020-08-17 22:22 #> Status: 200 #> Content-Type: application/json #> Size: 1.6 kB #> { #> "args": {}, #> "data": "", #> "files": { #> "y": "bibentry(\"Manual\",\n title = \"R: A Language and Environm... #> }, #> "form": {}, #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> ...#> Response [http://httpbin.org/post] #> Date: 2020-08-17 22:22 #> Status: 200 #> Content-Type: application/json #> Size: 565 B #> { #> "args": {}, #> "data": "{\"x\":\"A simple text string\"}", #> "files": {}, #> "form": {}, #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Content-Length": "28", #> "Content-Type": "application/json", #> ...# body can also be provided as a json string directly to deal # with specific case, like an empty element in the json string. # passing as string directly POST(b2, body = '{"a":1,"b":{}}', encode = "raw")#> Response [http://httpbin.org/post] #> Date: 2020-08-17 22:22 #> Status: 200 #> Content-Type: application/json #> Size: 503 B #> { #> "args": {}, #> "data": "{\"a\":1,\"b\":{}}", #> "files": {}, #> "form": {}, #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Content-Length": "14", #> "Host": "httpbin.org", #> ...# or building the json string before json_body <- jsonlite::toJSON(list(a = 1, b = NULL), auto_unbox = TRUE) POST(b2, body = json_body, encode = "raw")#> Response [http://httpbin.org/post] #> Date: 2020-08-17 22:22 #> Status: 200 #> Content-Type: application/json #> Size: 503 B #> { #> "args": {}, #> "data": "{\"a\":1,\"b\":{}}", #> "files": {}, #> "form": {}, #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Content-Length": "14", #> "Host": "httpbin.org", #> ...#> Response [http://httpbin.org/post] #> Date: 2020-08-17 22:22 #> Status: 200 #> Content-Type: application/json #> Size: 458 B #> { #> "args": {}, #> "data": "", #> "files": {}, #> "form": {}, #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Content-Length": "0", #> "Host": "httpbin.org", #> ...#> Response [http://httpbin.org/post] #> Date: 2020-08-17 22:22 #> Status: 405 #> Content-Type: text/html #> <EMPTY BODY>#> Response [http://httpbin.org/post] #> Date: 2020-08-17 22:22 #> Status: 200 #> Content-Type: application/json #> Size: 458 B #> { #> "args": {}, #> "data": "", #> "files": {}, #> "form": {}, #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Content-Length": "0", #> "Host": "httpbin.org", #> ...