curl:如何限制GET的大小? [英] curl: How to limit size of GET?
本文介绍了curl:如何限制GET的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从带有curl的URL中检索前10k个字节(在我的例子中使用PHP)。有没有办法指定这个?我认为CURLOPT_BUFFERSIZE会做到这一点,但它只是看起来确定一个缓冲区的大小,直到所有的内容都被检索。
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.
推荐答案
这是我在c ++中做的
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;
编辑:刚刚发现你的意思是在php。
Just found out you meant in php. Ill see if i can find out how to port it.
想想这应该可以在php中使用:
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") );
这篇关于curl:如何限制GET的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文