使用自定义标题批量下载文件

时间:2017-11-15 19:58:29

标签: batch-file download header

我试图从opentripplanner服务器下载大量的等时线。 限制是:无需外部工具或安​​装。客户端是Windows 7.要创建.bat文件,我使用自制的Excel工具。

默认响应是.json文件格式。这对bitsadmin来说效果很好:

bitsadmin /Transfer Download_Isochrone_1 /download /priority normal http://exampleserver.com/otp-rest-servlet/ws/isochrone?routerId=bordeaux^&algorithm=accSampling^&fromPlace=47.059,-0.880^&date=2013/10/01^&time=12:00:00^&maxWalkDistance=1000^&mode=WALK,TRANSIT^&cutoffSec=1800^&cutoffSec=3600 c:\username\downloads\Isochrone_1.json
bitsadmin /Transfer Download_Isochrone_2 /download /priority normal http://exampleserver.com/otp-rest-servlet/ws/isochrone?routerId=bordeaux^&algorithm=accSampling^&fromPlace=47.089,-0.881^&date=2013/10/01^&time=12:00:00^&maxWalkDistance=1000^&mode=WALK,TRANSIT&cutoffSec=1800^&cutoffSec=3600 c:\username\downloads\Isochrone_2.json
bitsadmin /Transfer Download_Isochrone_3 /download /priority normal http://exampleserver.com/otp-rest-servlet/ws/isochrone?routerId=bordeaux^&algorithm=accSampling^&fromPlace=47.159,-0.882^&date=2013/10/01^&time=12:00:00^&maxWalkDistance=1000^&mode=WALK,TRANSIT^&cutoffSec=1800^&cutoffSec=3600 c:\username\downloads\Isochrone_3.json

但是.shp(.zip)可以使用自定义标头。 ("接受:application / x-zip-compressed")。已经通过Browser-Plugin为单个等时线完成了这项工作。 所以我试过

bitsadmin /Create /Download Download_Isochrones
bitsadmin /SetCustomHeader Download_Isochrones "Accept: application/x-zip-compressed"
bitsadmin /Addfile Download_Isochrones http://exampleserver.com/otp-rest-servlet/ws/isochrone?routerId=bordeaux^&algorithm=accSampling^&fromPlace=47.059,-0.880^&date=2013/10/01^&time=12:00:00^&maxWalkDistance=1000^&mode=WALK,TRANSIT^&cutoffSec=1800^&cutoffSec=3600 c:\username\downloads\Isochrone_1.txt
bitsadmin /Addfile Download_Isochrones http://exampleserver.com/otp-rest-servlet/ws/isochrone?routerId=bordeaux^&algorithm=accSampling^&fromPlace=47.089,-0.881^&date=2013/10/01^&time=12:00:00^&maxWalkDistance=1000^&mode=WALK,TRANSIT&cutoffSec=1800^&cutoffSec=3600 c:\username\downloads\Isochrone_2.txt
bitsadmin /Addfile Download_Isochrones http://exampleserver.com/otp-rest-servlet/ws/isochrone?routerId=bordeaux^&algorithm=accSampling^&fromPlace=47.159,-0.882^&date=2013/10/01^&time=12:00:00^&maxWalkDistance=1000^&mode=WALK,TRANSIT^&cutoffSec=1800^&cutoffSec=3600 c:\username\downloads\Isochrone_3.txt
bitsadmin /Resume Download_Isochrones
bitsadmin /Complete Download_Isochrones

但它不起作用。实际上" / Addfile"似乎根本不能用于此目的。 (使用.txt扩展名进行测试) 是否有可能与/ setcustomheader组合/转移或我只是在上面的代码中犯了错误?或者没有win7外部工具可以做到这一点吗? 如有兴趣,请参阅OpenTripPlanner doc:http://dev.opentripplanner.org/apidoc/1.0.0/resource_LIsochrone.html

1 个答案:

答案 0 :(得分:2)

尝试winhttpjs.bat

call winhttpjs.bat "https://requestb.in/vp4p0gvp"  -headers-file headers.txt  -saveTo file.gzip

您需要在同一目录中使用headers.txt文件,如下所示:

#compression header
Accept: application/x-zip-compressed

要检查结果,我在test link网站上创建了一个https://requestb.in