当verbose = TRUE时从curl包捕获消息

时间:2017-02-24 02:19:33

标签: r

我需要捕获从各种curl函数输出的详细消息。

这是一个例子

testCurlCalls <- function(x){
  ## Setting up data vendor calls in parallel
  ###############################
  out <<- list()
  dbout <<- list()
  # This is function, function which will be run if data vendor call is successful
  complete = function(res){
      # cat("Request done! Status:", res$status, "\n")
      out <<- c(out, list(res))
  }

  error_out <<- list()

  error = function(res){
    # cat("Request done! Status:", res$status, "\n")
    error_out <<- c(error_out, list(res))
  }

  h1 <- new_handle(url = "https://httpbin.org/get", verbose = TRUE)
  handle_setopt(h1, customrequest = "GET")
  handle_setform(h1, a = "1", b = "2.1")

  multi_add(h1, done = complete, fail = error)

  result <- multi_run(timeout = 20)

  list(
    result = result
    ,status_codes = sapply(out, function(x){x$status_code})
  )

}

运行该功能时,信息将在控制台中打印出来

testCurlCalls()


#* Found bundle for host httpbin.org: 0x1023ae750
#* Re-using existing connection! (#6) with host httpbin.org
#* Connected to httpbin.org (23.22.14.18) port 443 (#6)
#> GET /get HTTP/1.1
#Host: httpbin.org
#User-Agent: r/curl/jeroen
#Accept: */*
#Accept-Encoding: gzip, deflate
#Content-Length: 230
#Expect: 100-continue
#Content-Type: multipart/form-data; boundary=------------------------932f59dc122a07ac

#< HTTP/1.1 100 Continue
#< HTTP/1.1 200 OK
#< Server: nginx
#< Date: Fri, 24 Feb 2017 02:16:35 GMT
#< Content-Type: application/json
#< Content-Length: 355
#< Connection: keep-alive
#< Access-Control-Allow-Origin: *
#< Access-Control-Allow-Credentials: true
#< 
#* Connection #6 to host httpbin.org left intact
#$result
#$result$success
#[1] 1
#
#$result$error
#[1] 0
#
#$result$pending
#[1] 0
#
#
#$status_codes
#[1] 200

但我似乎无法弄清楚如何捕获消息。

0 个答案:

没有答案