This function is only for testing purposes. It starts a local httpuv server to echo the request body and content type in the response.

curl_echo(handle, port = 9359, progress = interactive(), file = NULL)

Arguments

handle

a curl handle object

port

the port number on which to run httpuv server

progress

show progress meter during http transfer

file

path or connection to write body. Default returns body as raw vector.

Examples

h <- new_handle(url = 'https://httpbin.org/post') handle_setform(h, foo = "blabla", bar = charToRaw("test"), myfile = form_file(system.file("DESCRIPTION"), "text/description")) # Echo the POST request data formdata <- curl_echo(h) # Show the multipart body cat(rawToChar(formdata$body))
#> --------------------------a76041db4284d688 #> Content-Disposition: form-data; name="foo" #> #> blabla #> --------------------------a76041db4284d688 #> Content-Disposition: form-data; name="bar" #> #> test #> --------------------------a76041db4284d688 #> Content-Disposition: form-data; name="myfile"; filename="DESCRIPTION" #> Content-Type: text/description #> #> Package: base #> Version: 3.6.1 #> Priority: base #> Title: The R Base Package #> Author: R Core Team and contributors worldwide #> Maintainer: R Core Team <[email protected]> #> Description: Base R functions. #> License: Part of R 3.6.1 #> Suggests: methods #> Built: R 3.6.1; ; 2019-07-06 02:01:41 UTC; unix #> #> --------------------------a76041db4284d688--
# Parse multipart webutils::parse_http(formdata$body, formdata$content_type)
#> $foo #> $foo$value #> [1] 62 6c 61 62 6c 61 #> #> $foo$content_disposition #> [1] "form-data" #> #> $foo$name #> [1] "foo" #> #> #> $bar #> $bar$value #> [1] 74 65 73 74 #> #> $bar$content_disposition #> [1] "form-data" #> #> $bar$name #> [1] "bar" #> #> #> $myfile #> $myfile$value #> [1] 50 61 63 6b 61 67 65 3a 20 62 61 73 65 0a 56 65 72 73 69 6f 6e 3a 20 33 2e #> [26] 36 2e 31 0a 50 72 69 6f 72 69 74 79 3a 20 62 61 73 65 0a 54 69 74 6c 65 3a #> [51] 20 54 68 65 20 52 20 42 61 73 65 20 50 61 63 6b 61 67 65 0a 41 75 74 68 6f #> [76] 72 3a 20 52 20 43 6f 72 65 20 54 65 61 6d 20 61 6e 64 20 63 6f 6e 74 72 69 #> [101] 62 75 74 6f 72 73 20 77 6f 72 6c 64 77 69 64 65 0a 4d 61 69 6e 74 61 69 6e #> [126] 65 72 3a 20 52 20 43 6f 72 65 20 54 65 61 6d 20 3c 52 2d 63 6f 72 65 40 72 #> [151] 2d 70 72 6f 6a 65 63 74 2e 6f 72 67 3e 0a 44 65 73 63 72 69 70 74 69 6f 6e #> [176] 3a 20 42 61 73 65 20 52 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 4c 69 63 65 6e #> [201] 73 65 3a 20 50 61 72 74 20 6f 66 20 52 20 33 2e 36 2e 31 0a 53 75 67 67 65 #> [226] 73 74 73 3a 20 6d 65 74 68 6f 64 73 0a 42 75 69 6c 74 3a 20 52 20 33 2e 36 #> [251] 2e 31 3b 20 3b 20 32 30 31 39 2d 30 37 2d 30 36 20 30 32 3a 30 31 3a 34 31 #> [276] 20 55 54 43 3b 20 75 6e 69 78 0a #> #> $myfile$content_disposition #> [1] "form-data" #> #> $myfile$content_type #> [1] "text/description" #> #> $myfile$name #> [1] "myfile" #> #> $myfile$filename #> [1] "DESCRIPTION" #> #>