- 论坛徽章:
- 0
|
原帖由 福瑞哈哥 于 2007-7-11 09:39 发表 ![]()
不管服务器是否采用了chunked传输
我加了一小段程序测试是不是chunked传输,但是没有反应,不知道是不是写错了?:
if ((tmp = strstr(strResponse, CHUNKED)) == NULL)
flag = 0;
else
flag = 1;
if (flag == 1)
printf ("find chunk");
即全程序如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <zlib.h>
#define BUFSIZE 10240
#define CHUNKED "Transfer-Encoding: chunked\r\n"
#define DestIp "58.61.166.67"
#define DestPort 80
#define Req "GET /cgi-bin/qqshow_user_searchitem?search_str=搞怪&style=1&nowpage=1&sorttype=0&content=&sex=0 HTTP/1.1\r\nAccept: */*\r\nAccept-Language: zh-cn\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)\r\nHost: 58.61.166.67\r\nConnection: Keep-Alive\r\nCookie: pvid=1250811316; edition=4m16.mail.qq.com; CCSHOW=0000; ruv=3715021559298\r\n\r\n"
#define ReqLen sizeof(Req)
int main(int argc, char *argv[])
{
ssize_t i;
int nRequestLen;
int templen = 0;
int flag = -1;
char *tmp = NULL;
int c;
gzFile file, zip;
Byte compr[BUFSIZE], uncompr[BUFSIZE];
uLong comprLen, uncomprLen;
char strResponse[BUFSIZE]={0};
char strRequest[BUFSIZE]={0};
char strGzip[BUFSIZE]={0};
char *pA = NULL;
int sockfd, numbytes;
struct sockaddr_in dest_addr; /* connector's address information */
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(1);
}
dest_addr.sin_family = AF_INET; /* host byte order */
dest_addr.sin_port = htons(DestPort); /* short, network byte order */
dest_addr.sin_addr.s_addr = inet_addr(DestIp);
/* Create and setup the connection */
if (connect(sockfd, (struct sockaddr *)&dest_addr,sizeof(struct sockaddr)) == -1) {
perror("connect");
exit(1);
}
/* Send the request */
strncpy(strRequest, Req,ReqLen);
nRequestLen = ReqLen;
if (write(sockfd,strRequest,nRequestLen) == -1) {
perror("write");
exit(1);
}
/* Read in the response */
while(1) {
i = read(sockfd,strResponse + templen,BUFSIZE-1);
if(0 >= i){
break;
}
//strResponse='\0';
templen = templen + i;
}
printf(strResponse);
pA = strstr(strResponse, "\r\n\r\n");
if ((tmp = strstr(strResponse, CHUNKED)) == NULL)
flag = 0;
else
flag = 1;
if (flag == 1)
printf ("find chunk");
printf("%d\n", templen);
printf("%d\n", pA - strResponse);
printf(pA);
memcpy(strGzip, pA + 4, templen - ((pA - strResponse) + 4));
printf("\nooooooo\n");
//gzprintf(file, strGzip);
//comprLen = sizeof(file) / sizeof(compr[0]);
comprLen = (templen - ((pA - strResponse) +4));
printf("%d\n", comprLen);
//strcpy((char *)uncompr, "garbage");
/*int err = uncompress(uncompr, &uncomprLen, (const Bytef*)strGzip, comprLen);
if (err != Z_OK){
printf("uncompress error:%d\n", err);
exit(1);
}*/
/* Close the connection */
close(sockfd);
} |
|