从终端GET工作 但httr::GET不

我试图从httr::GET的服务器下载 rasters,我们曾经有这个工作,但对服务器进行了一些更改,现在它不起作用。

我试图从httr::GET的服务器下载 rasters,我们曾经有这个工作,但对服务器进行了一些更改,现在它不起作用。

通过浏览器或通过终端(ubuntu 16.04)中的 GET 使用 URL 工作正常,并返回一个工作 tif raster。但是使用来自httr::GET的相同 url 不起作用,并给出Status: 400

我唯一的猜测是它与数据的编码有关。但我真的不确定。

file <- paste0(tempdir(), '/file.tif')
r <- 
  httr::GET('https://map.ox.ac.uk/geoserver/Explorer/ows?service=WCS&version=2.0.1&request=GetCoverage&format=image/geotiff&coverageid=2015_Nature_Africa_PR&SUBSET=Long(-3,50.483779907)&SUBSET=Lat(-25.6089496609999,-11.9454326629999)&SUBSET=time(\"2015-01-01T00:00:00.000Z\")',
           httr::write_disk(file, overwrite = TRUE))
ras <- raster::raster(file)
# I'm now totally confused about when and where quotes are escaped, so just to make sure...
r <- 
  httr::GET('https://map.ox.ac.uk/geoserver/Explorer/ows?service=WCS&version=2.0.1&request=GetCoverage&format=image/geotiff&coverageid=2015_Nature_Africa_PR&SUBSET=Long(-3,50.483779907)&SUBSET=Lat(-25.6089496609999,-11.9454326629999)&SUBSET=time("2015-01-01T00:00:00.000Z")',
            httr::write_disk(file, overwrite = TRUE))
ras <- raster::raster(file)
# But just putting the url in the browser works fine.
# https://map.ox.ac.uk/geoserver/Explorer/ows?service=WCS&version=2.0.1&request=GetCoverage&format=image/geotiff&coverageid=2015_Nature_Africa_PR&SUBSET=Long(-3,50.483779907)&SUBSET=Lat(-25.6089496609999,-11.9454326629999)&SUBSET=time("2015-01-01T00:00:00.000Z")
# eg 
# rr <- raster::raster('~/Desktop/2015_Nature_Africa_PR3.tif')
# And using the URL with GET in the terminal works
# GET "https://map.ox.ac.uk/geoserver/Explorer/ows?service=WCS&version=2.0.1&request=GetCoverage&format=image/geotiff&coverageid=2015_Nature_Africa_PR&SUBSET=Long(-3,50.483779907)&SUBSET=Lat(-25.6089496609999,-11.9454326629999)&SUBSET=time(\"2015-01-01T00:00:00.000Z\")" > ~/Desktop/2015_Nature_Africa_PR4.tif
# eg
# rr <- raster::raster('~/Desktop/2015_Nature_Africa_PR4.tif')
5

包装在URLEncode为我工作:

library(httr)
library(raster)
file <- paste0(tempdir(), '/file.tif')
url1 <- 'https://map.ox.ac.uk/geoserver/Explorer/ows?service=WCS&version=2.0.1&request=GetCoverage&format=image/geotiff&coverageid=2015_Nature_Africa_PR&SUBSET=Long(-3,50.483779907)&SUBSET=Lat(-25.6089496609999,-11.9454326629999)&SUBSET=time("2015-01-01T00:00:00.000Z")'
r   <- GET(URLencode(url1), write_disk(file, overwrite = TRUE))
ras <- raster(file)

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(525)
如何快速连续安装IIS服务器和托管包 而不会遇到错误
上一篇
在客户端拦截来自和去往Web服务的SOAP消息
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(25条)