0

I'm behind a VPN. And I think whoever administers it must have done some weird change lately because suddenly my script doesn't work.

It's not terribly important to know what the below is doing, basically logging into SFDC so that I can later download a CSV..

The point is that if I were to simply plop in the url string (https://login.salesforce.com/?un=username@domain.com&pw=password) into my web browser, it will work no problem. So why, with the EXACT same URL, is R unable to connect to host?

library(RCurl)

agent="Firefox/23.0" 

options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))
curl = getCurlHandle()

curlSetOpt(
  cookiejar = 'cookies.txt' ,
  useragent = agent,
  followlocation = TRUE ,
  autoreferer = TRUE ,
  curl = curl
)
un="username@domain.com"
pw="password"

html = postForm(paste("https://login.salesforce.com/?un=", un, "&pw=", pw, sep=""), curl=curl)
wizard_draziw
  • 505
  • 1
  • 5
  • 17
  • 1
    There's more to an HTTP request than just a URL. Servers may process requests differently based on user-agents or other HTTP headers. It would be a good idea to look at the full browser HTTP request (you can use the Developer Tools in Chrome for example to do this). Then make sure you've set up RCurl to mimic the exact same headers. – MrFlick May 08 '15 at 22:58
  • Sorry for the late reply. This is still bogging me down and I feel like I've tried everything. I am behind a VPN but I don't think I'm through a Proxy server. – wizard_draziw May 20 '15 at 15:25
  • I checked the Developer Tools and logged in by using the URL (with the ?un=??? etc) and it traced all the files etc. But I'm not exactly sure how to go about mimicing headers in R? I'm pretty good with R but HTTP protocols still mystify me – wizard_draziw May 20 '15 at 15:26
  • Maybe [this answer](http://stackoverflow.com/questions/25173211/r-disparity-between-browser-and-get-geturl/25173807#25173807) can help. Check all the [HTTP headers](http://stackoverflow.com/questions/4423061/view-http-headers-in-google-chrome). Without a fully reproducible example it's hard to help. Every website is different. – MrFlick May 20 '15 at 15:30
  • Oops! I'm wrong I *AM* behind a proxy! I'm going to answer my own question in case it helps others – wizard_draziw May 20 '15 at 15:34

1 Answers1

0

Alright I'm answering this myself because I finally figured it out!

I found that Internet Explorer had a Configuration Script. I mistakingly was using this script location as the proxy. I dived into the script and actually noticed that there was a variable that looked like a proper proxy. Once I popped that into my curlSetOpt, everything worked as it should!

In case anyone is wondering, add this:

curlSetOpt(
  cookiejar = 'cookies.txt' ,
  useragent = agent,
  followlocation = TRUE ,
  autoreferer = TRUE ,
  curl = curl,
 .opts = list(proxy="proxylocation.com:8080")

)

wizard_draziw
  • 505
  • 1
  • 5
  • 17