Open sckott opened 8 years ago
Hi @sckott !
I am resuming development on the package which was frozen for a while to other urgent projects. I decided to start with using httr
instead of RCurl
but ran into difficulties right away. I think it is an authentication problem.
For example, I was trying to replace the line
RCurl::getURL( paste( options$server_url, "/protocol", sep = "" ), verbose = FALSE, userpwd = options$userpwd, httpauth = 1L)
which is in repository_information.R
with the appropriate httr
call and came up with the following (I've hard-wired the password for testing purposes for now - I will change it as soon as I troubleshoot the problem):
httr::GET( paste( options$server_url, "/protocol", sep = "" ) , authenticate( "obkms", "1obkms", "basic"), verbose() )
However, this does not seem to work, as it produces the following output:
> r = httr::GET( request_url , authenticate( "obkms", "1obkms", "basic"), verbose() )
-> GET /graphdb/protocol HTTP/1.1
-> Host: 213.191.204.69:7777
-> Authorization: Basic b2JrbXM6MW9ia21z
-> User-Agent: libcurl/7.47.0 r-curl/0.9.7 httr/1.2.0
-> Accept-Encoding: gzip, deflate
-> Cookie: JSESSIONID=92BCB4C5F5004C8CC4FBF673A02CD280
-> Accept: application/json, text/xml, application/xml, */*
->
<- HTTP/1.1 200 OK
<- Server: Apache-Coyote/1.1
<- Content-Type: text/plain;charset=UTF-8
<- Content-Language: en-US
<- Content-Length: 1
<- Date: Fri, 07 Oct 2016 08:32:09 GMT
<-
I played around and if I enter the wrong password, I pretty much the same empty result. I also remember that when I was using the getURL
function from RCurl
before, I had to add the option httpauth = 1L
for it to work. As far as I understand, this means "basic authentication." Just to make sure I tried all the other types of authentication from the httr:GET
manpage to no avail.
Do you have any idea where the problem might be coming from?
Best Vic
I think all you need to do is content(r)
to get the output. The output from a call to any of the http verb functions (e.g., GET
) is a object of class response
, with the output, headers, status code, etc. Then you call content
on it to get back outout. Best practice to usually get back plain text like content(r, as = "text")
then parse the text according to what type of data it is (e.g., for xml use xml2
package, for JSON data use jsonlite
package)
@sckott many thanks for that! I guess I should have RTFM more carefully before asking! Sry :)
no problem!
httr
is best practice package now for HTTP requests in R -RCurl
is okay, but will probably not be maintained very well moving forward