Rcurl Geturlcontent Detect Content Type Through Final Redirect
Solution 1:
Maybe there's a better solution, but one way could be this:
# ...
h <- basicTextGatherer()
x = getBinaryURL('http://timesofindia.indiatimes.com//articleshow/2933019.cms',
headerfunction = h$update, curl = curl)
r <- gregexpr("Content-Type:.*?\n", h$value())
tail(regmatches(h$value(), r)[[1]], 1)
# [1] "Content-Type: application/pdf\r\n"
Solution 2:
I have run into a similar issue trying to run getURLContent using digest authentication to get at binary data (using a non-standard mime type). I am running RCurl v1.95-4.1 on R 2.15.3.
If I run getURLContent without the binary=TRUE flag, it won't autoswitch to binary=TRUE because of the mime header for this data type, so it attempts to perform a rawToChar() and throws a 'embedded NULL in string' error. However the authentication does work.
If I add a binary=TRUE flag to the getURLContent call, it seems to cause issues with the authentication step, since I then get an 'Error: Unauthorized' response.
What finally worked was to replace getURLContent() with getBinaryURL() [as in the example above], which allowed the userpwd="u:p" authorization to work and delivered the binary data to my assigned object.
I think that the author of RCurl has made improvements to getURLContent's handling of binary data for v1.97, based on what I see in GitHub, so this may become a thing of the past...except for those of us still running older R setups.
Post a Comment for "Rcurl Geturlcontent Detect Content Type Through Final Redirect"