douxu2081 2009-06-12 07:27
浏览 191
已采纳

curl:如何限制GET的大小?

I want to retrieve the first 10k bytes from a URL with curl (using PHP in my case). Is there a way to specify this? I thought CURLOPT_BUFFERSIZE would do this, but it just appears to determine the size of a buffer that is reused until all of the content is retrieved.

  • 写回答

5条回答 默认 最新

  • douxi0098 2009-06-12 07:33
    关注

    This is how i do it in c++

    int offset = 0;
    int size = 10*1024;
    
    char range[256];
    curl_slist_s *pHeaders = NULL;
    snprintf(range, 256, "Range: bytes=%d-%d", offset, offset+size-1);
    
    pHeaders = curl_slist_append(pHeaders, range);
    curl_easy_setopt(pCurlHandle, CURLOPT_HTTPHEADER, pHeaders);
    
    curl_slist_free_all(pHeaders);
    pHeaders = NULL;
    

    Edit: Just found out you meant in php. Ill see if i can find out how to port it.

    Think this should work in php:

    $offset = 0;
    $size = 10*1024;
    
    $a = $offset;
    $b = $offset + $size-1;
    
    curl_easy_setopt(curlHandle, CURLOPT_HTTPHEADER, array("Range: bytes=$a-$b") );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记