R

[R] HTTP Client - httr

'김용환' 2015. 8. 3. 20:21



R에는 httr 이라는 HTTP Client api가 존재한다. keep-alive를 지원하며, 때에 따라 성능이 빠르다.


예제 1)- get

library(httr) 

r <- GET("http://www.naver.com")

r$status_code

r$cookies

r$request



예제 2)- post


#install(httr)

library(httr) 


user <- "samuel"

password <- "sam8a2" 

POST(url = 'http://localhost/login',      

config = c(authenticate(user, password, "basic"), 

add_headers(Connection = "keep-alive"),

accept_json()),      

body = "{'auth-key:'sadfasdf1231'}"

)