httr

Post request using cookies with cURL, RCurl and httr

不想你离开。 提交于 2019-12-03 08:44:16
In Windows cURL I can post a web request similar to this: curl --dump-header cook.txt ^ --data "RURL=http=//www.example.com/r&user=bob&password=hello" ^ --user-agent "Mozilla/5.0" ^ http://www.example.com/login With type cook.txt I get a response similar to this: HTTP/1.1 302 Found Date: Thu, ****** Server: Microsoft-IIS/6.0 SERVER: ****** X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Location: ****** Set-Cookie: Cookie1=; domain=******; expires=****** ****** ****** ****** Cache-Control: private Content-Type: text/html; charset=iso-8859-1 Content-Length: 189 I can manually read cookie lines

R Change IP Address programmatically

纵饮孤独 提交于 2019-12-03 08:02:04
问题 Currently changing user_agent by passing different strings to the html_session() method. Is there also a way to change your IP address on a timer when scraping a website? 回答1: You can use a proxy (which changes your ip) via use_proxy as follows: html_session("you-url", use_proxy("proxy-ip", port)) For more details see: ?httr::use_proxy To check if it is working you can do the following: require(httr) content(GET("https://ifconfig.co/json"), "parsed") content(GET("https://ifconfig.co/json",

Using an API to calculate distance between two airports (two columns) within R?

拈花ヽ惹草 提交于 2019-12-03 07:52:15
I was wondering whether there was a way to compare airport distances(IATA codes). There are some scripts but not is using R. So I tried that with with the API: developer.aero Example data: library(curl) # for curl post departure <- c("DRS","TXL","STR","DUS","LEJ","FKB","LNZ") arrival <- c("FKB","HER","BOJ","FUE","PMI","AYT","FUE") flyID <- c(1,2,3,4,5,6,7) df <- data.frame(departure,arrival,flyID) departure arrival flyID 1 DRS FKB 1 2 TXL HER 2 3 STR BOJ 3 4 DUS FUE 4 5 LEJ PMI 5 6 FKB AYT 6 7 LNZ FUE 7 api<- curl_fetch_memory("https://airport.api.aero/airport/distance/DRS/FUE?user_key

Multi POST query (session mode)

喜夏-厌秋 提交于 2019-12-03 05:20:46
I am trying to interrogate this site to get the list of offers. The problem is that we need to fill 2 forms (2 POST queries) before receiving the final result. This what I have done so far: First I am sending the first POST after setting the cookies: library(httr) set_cookies(.cookies = c(a = "1", b = "2")) first_url <- "https://compare.switchon.vic.gov.au/submit" body <- list(energy_category="electricity", location="home", "location-home"="shift", "retailer-company"="", postcode="3000", distributor=7, zone=1, energy_concession=0, "file-provider"="", solar=0, solar_feedin_tariff="", disclaimer

R Change IP Address programmatically

感情迁移 提交于 2019-12-02 21:30:26
Currently changing user_agent by passing different strings to the html_session() method. Is there also a way to change your IP address on a timer when scraping a website? You can use a proxy (which changes your ip) via use_proxy as follows: html_session("you-url", use_proxy("proxy-ip", port)) For more details see: ?httr::use_proxy To check if it is working you can do the following: require(httr) content(GET("https://ifconfig.co/json"), "parsed") content(GET("https://ifconfig.co/json", use_proxy("138.201.63.123", 31288)), "parsed") The first call will return your IP. The second call should

httr POST request to API returns 400 error

天涯浪子 提交于 2019-12-02 10:22:21
问题 I'm working with the httr package in R in an attempt to query the postcode.io API (http://postcodes.io/docs). I can successfully query a single postcode as per the instructions using: sample4 <- GET("api.postcodes.io/postcodes/EN14RF") When I try and query multiple postcodes I'm becoming a little unstuck. The postcode.io instructions suggest POST https://api.postcodes.io/postcodes?q=[postcode] where a JSON object containing an array of postcodes is specified. I have an R vector containing

How to make a POST request with header and data options in R using httr::POST?

╄→尐↘猪︶ㄣ 提交于 2019-12-02 08:33:31
I am trying make a POST request with data and header information using httr::POST . I can see how to make a POST request , but I am unable to get it to work with curl's data ( -d ) and header ( -H ) options. This works perfectly in my terminal (obviously with different data/api, but exactly the same format) curl -H "Accept: application/json" -H "Content-type: application/json" -d '{"name": "Fred", "age": "5"}' "http://www.my-api.com" Question How can the above POST request be made (with headers and data) using httr::POST ? What I've tried so far library(jsonlite) my_data <- list(name="Fred",

Array in body for httr POST request

混江龙づ霸主 提交于 2019-12-02 07:38:48
问题 This curl call works to create a new droplet on Digital Ocean curl -X POST "https://api.digitalocean.com/v2/droplets" \ -d '{"name":"test3","region":"nyc2","size":"512mb","image":5562742,"ssh_keys":[89103]}' \ -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" However, I'm having trouble getting an httr::POST() request to work only when the parameter ssh_keys is given. In the above method the ssh_keys parameter, if given, has to be an array. I assumed the list of parameters

Get site content over SSL with httr in R

家住魔仙堡 提交于 2019-12-02 05:47:38
I'm trying to fetch a JSON array from my server using the HTTP POST method in R. I've tried using both the POST function from httr and the getURL function from RCurl but both return errors. cafile <- system.file("CurlSSL", "cacert.pem", package = "RCurl") url <- "https://example.com/query/getData.php" POST(url,body=NULL) POST(url,body=NULL,config(cainfo=cafile)) getURL(url) getURL(url,cainfo=cafile) The error given by the POST function is (for both calls): Error in curl::curl_fetch_memory(url, handle = handle) : SSL peer certificate or SSH remote key was not OK The error given by the getURL

Array in body for httr POST request

有些话、适合烂在心里 提交于 2019-12-02 03:48:19
This curl call works to create a new droplet on Digital Ocean curl -X POST "https://api.digitalocean.com/v2/droplets" \ -d '{"name":"test3","region":"nyc2","size":"512mb","image":5562742,"ssh_keys":[89103]}' \ -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" However, I'm having trouble getting an httr::POST() request to work only when the parameter ssh_keys is given. In the above method the ssh_keys parameter, if given, has to be an array. I assumed the list of parameters could be passed to the body as, e.g., where the ssh_keys parameter is inside a list args <- list(name=