Last active
          August 29, 2015 14:17 
        
      - 
      
- 
        Save jeroen/b053fd18c8a8421d682f to your computer and use it in GitHub Desktop. 
    How to do stuff in curl
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | library(curl) | |
| # Verbose | |
| h <- new_handle() | |
| handle_setopt(h, verbose = TRUE) | |
| req <- curl_perform("http://httpbin.org/get", handle = h) | |
| # Parsing headers | |
| parse_headers(req$headers) | |
| # Streaming with a callback function: | |
| get_with_callback <- function(url, cb){ | |
| con <- curl(url) | |
| open(con, "rb") | |
| on.exit(close(con)) | |
| while(length(buf <- readBin(con, raw(), n = 8000))){ | |
| cb(buf) | |
| } | |
| invisible() | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment