我試圖解析以下HTTP響應:Ç初學者:字符串解析
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
我想提取「48」和二進制內容。
這裏就是我試過SOFAR:
//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");
}
但我現在有點粘...任何幫助是極大的讚賞。
編輯:
這裏就是我做SOFAR:
char* pch;
char* pch2;
pch=strstr(buf,"Content-Length:");
pch2=strstr(pch,"\r\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));
你可以檢查http://curl.haxx.se/libcurl/c/和'CURLOPT_WRITEHEADER'選項 – Cyclonecode
我想避免使用捲曲。我正在做一切使用套接字... – Eamorr