确定服务器是否支持恢复获取请求 [英] determine if server supports resume get request

查看:219
本文介绍了确定服务器是否支持恢复获取请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定服务器是否支持恢复文件传输或获取请求?

How does one determine if a server supports resuming a file transfer or get request?

我的想法是设置头文件以2字节开始获取请求而不是0,并且立即关闭http请求,如果给出了正确的结果

My thoughts were to set the header to start the get request at byte "2" instead of 0, and immediately closing the http request if that gave the proper result

但我想知道是否有一些关于服务器响应的另一种探针这将向我显示这个信息

but I was wondering if there was something about the server response for a different kind of probe that would reveal this information to me

推荐答案

要探测服务器的下载恢复功能,您可以向服务器为Range标头提供任意值。如果回复代码为206,则支持简历。

To probe the download resume feature of a server, you may send a HEAD request to the server supplying a Range header with arbitrary values. If the response code is 206, then resume is supported.

卷曲示例:

$ curl -i -X HEAD --header范围:bytes = 50-100http://mirrors.melbourne.co.uk/ubuntu-releases//raring/ubuntu-13.04-desktop-amd64.iso

更新:

import org.apache.http.client.ResponseHandler;
import org.apache.http.client.HttpClient;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;

public class ResumeChecker {

    public final static void main(String[] args) throws Exception {

        HttpClient httpclient = new DefaultHttpClient();
        HttpHead httpRequest = new HttpHead("http://www.google.com");
        httpRequest.addHeader(new BasicHeader("Range", "bytes=10-20"));

        System.out.println("Executing request " + httpRequest.getURI());

        HttpResponse response = httpclient.execute(httpRequest);

        // Check here that response.getStatusLine() contains 206 code
    }
}

但是,我还没有测试过mysqlf。

However, I haven't tested it mysqlf.

这篇关于确定服务器是否支持恢复获取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆