Movatterモバイル変換


[0]ホーム

URL:


sched package helper functions

Here we present some functions, that may ease the usage of thesched package, or serve related purposes.

make_post_request()

This function facilitates the creation ofRequest objectfor a POST request.

Here is an example:

my_url<- sched::URL$new("https://httpbin.org/anything")my_request<- sched::make_post_request(my_url,body ="{\"some_key\":\"my_value\"}",mime ="application/json")

TheRequest object can then be used inside an URLrequest function:

res<- sched::get_url_request_result(my_request)res$getContent()#> [1] "{\n  \"args\": {}, \n  \"data\": \"{\\\"some_key\\\": \\\"my_value\\\"}\", \n  \"files\": {}, \n  \"form\": {}, \n  \"headers\": {\n    \"Accept\": \"application/json,multipart/*\", \n    \"Content-Length\": \"24\", \n    \"Content-Type\": \"application/json;charset=utf-8\", \n    \"Host\": \"httpbin.org\", \n    \"X-Amzn-Trace-Id\": \"Root=1-66fbf6c9-5dc0edcd6466a5822b0d48e9\"\n  }, \n  \"json\": {\n    \"some_key\": \"my_value\"\n  }, \n  \"method\": \"POST\", \n  \"origin\": \"195.83.222.29\", \n  \"url\": \"https://httpbin.org/anything\"\n}\n"

get_url_request_result()

This function is a plain URL requester, that donotuse thescheduling system of the package. It ispresented here as a convenience.

The function takes asched::Request object as input,along with standard parameters like:

Here is an example of usage:

my_url<- sched::URL$new("https://httpbin.org/get")my_request<- sched::Request$new(my_url)sched::get_url_request_result(my_request)#> <RequestResult>#>   Public:#>     clone: function (deep = FALSE)#>     getContent: function ()#>     getErrMsg: function ()#>     getLocation: function ()#>     getRetry: function ()#>     getRetryAfter: function ()#>     getStatus: function ()#>     initialize: function (content = NULL, retry = FALSE, err_msg = NULL, status = 0,#>     processRequestErrors: function ()#>   Private:#>     addErrMsg: function (msg)#>     content: {#>       "args": {},#>       "headers": {#>         "Accept": "*/*",#>        ...#>     err_msg: NULL#>     location: NULL#>     retry: FALSE#>     retry_after: NULL#>     status: 200#>     status_msg:

[8]ページ先頭

©2009-2025 Movatter.jp