curl-library
Re: buffer gets lost
Date: Sat, 14 Jan 2012 08:55:10 -0800
On Sat, Jan 14, 2012 at 09:49:20AM -0200, Marco wrote:
> Hello again, my CURLOPT_WRITEFUNCTION function is working just fine
> to write on buffer with any HTML page, but when I try to do it with
> any XML page, it simply cut off the very beginning of the page.
>
> CURLOPT_WRITEFUNCTION is writer(char *data, size_t size, size_t
> nmemb, std::string *buffer)
>
> I've took to stdout every char*data that curl inserted in the
> function, but i didn't showed the beginning of the xml source. Like
> this:
>
> int curlWrapper::writer(char *data, size_t size, size_t nmemb, string
> *buffer)
> {
> puts(data);
> buffer->append(data);
These aren't valid uses of the data pointer, since the data won't necessarily
be NUL-terminated. The code needs to append only size*nmemb bytes starting
at data.
> return size * nmemb;
> }
>
> Even when I try setting CURLOPT_FOLLOWLOCATION to 1, the buffer
> variable simply skip the beginning of the xml page like that:
>
> HTTP/1.1 200 OK
> Date: Sat, 14 Jan 2012 11:25:16 GMT
> Server: Microsoft-IIS/6.0
> X-Powered-By: ASP.NET
> X-AspNet-Version: 1.1.4322
> Set-Cookie: ASP.NET_SessionId=j0pegezsrkktzj45crfa0gea; path=/
> Cache-Control: private
> Expires: Sat, 14 Jan 2012 11:25:15 GMT
> Content-Type: text/xml; charset=iso-8859-1
> Content-Length: 1496
>
> Sabado><Erro>0</Erro><MsgErro></MsgErro></cServico><cServico><Codigo>41068</Codigo><Valor>7,86</Valor><PrazoEntrega>4</PrazoEntrega><ValorMaoPropria>0,00</ValorMaoPropria><ValorAvisoRecebimento>0,00</ValorAvisoRecebimento><ValorValorDeclarado>0,00</ValorValorDeclarado><EntregaDomiciliar>S</EntregaDomiciliar><EntregaSabado>N</EntregaSabado><Erro>0</Erro><MsgErro></MsgErro></cServico></Servicos>
>
>
> Does anyone know the reason for that behaviour?
You're probably seeing old data in the buffer, past the end of the valid area.
>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-01-14