curl-library
Problems in redirection
Date: Wed, 25 Mar 2009 12:51:50 +0800 (CST)
hi,
I am using curl to download some pages ,and i register a callback fucntion of CURLOPT_WRITEFUNCTION that will write the page content into a buffer ,it looks like this:
int writer(char *data, size_t size, size_t nmemb, string* writerData)
{
if(writerData==NULL)
{
return 0;
}
writerData->append(data,size*nmemb);
if(writerData->length()>PoolCurl::m_maxContent)
{
return 0;
}
return size*nmemb;
}
You can see ,i sotore all the content of web in a buffer named writerData.
when i download http://google.cn ,it returns 302 code ,so i use the CURLOPT_FOLLOWLOCATION option to follow the redirected url.
The curl follow the url successfully and the curl get the page http://www.google.cn for me ,but the problem now is that the writerData contains both the content of http://google.cn and http://www.google.cn, it looks like this:
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.cn/">here</A>.
</BODY></HTML>
<HTML>
The content of http://www.google.cn
.....
</HTML>
well ,now I don't want the content of the http://google.cn ,how can i do this ?
Thanks for any help.
Received on 2009-03-25