Estoy tratando de analizar la siguiente respuesta HTTP:C principiante: procesamiento de cadenas
HTTP/1.1 200 OK
Date: Tue, 06 Dec 2011 11:15:21 GMT
Server: Apache/2.2.14 (Ubuntu)
X-Powered-By: PHP/5.3.2-1ubuntu4.9
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 48
Content-Type: text/html
��(�ͱ���I�O����H�����ч��
�4�@�B�$���S
Quiero extraer "48" y el contenido binario.
Aquí es lo que he intentado hasta la fecha se:
//char* str contains the response
char * pch;
printf ("Splitting response into tokens:\n");
pch = strtok (str,"\r\n");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, "\r\n");
}
Pero estoy un poco atascado ahora ... Cualquier ayuda es muy apreciada.
edición:
Esto es lo que he hecho hasta la fecha se:
char* pch;
char* pch2;
pch=strstr(buf,"Content-Length:");
pch2=strstr(pch,"\r\n");
¿Cómo puedo obtener el bit entre estos dos punteros?
Editar: Solución:
char* pch;
char* pch2;
pch=strstr(buf,"Content-Length:");
int i=0;
char contLen[20];
for(i=0;i<20;i++){
char next=pch[strlen("Content-Length:")+i];
if(next=='\r' || next=='\n'){
break;
}
contLen[i]=next;
}
printf("%d\n",atoi(contLen));
Puede consultar http://curl.haxx.se/libcurl/c/ y la opción 'CURLOPT_WRITEHEADER' – Cyclonecode
Quiero evitar el uso de CURL. Estoy haciendo todo usando sockets ... – Eamorr