就是用c语言的写的一个简单http请求,并分析其响应,原理很简单,主要是分析http响应,麻烦的是提取其中的比赛信息
#define USERAGENT \"Wget/1.10.2\"
#define ACCEPT \"*/*\"
#define ACCEPTLANGUAGE \"zh-cn,zh;q=0.5\"
#define ACCEPTENCODING \"gzip,deflate\"
#define ACCEPTCHARSET \"gb2312,utf-8;q=0.7,*;q=0.7\"
#define KEEPALIVE \"300\"
#define CONNECTION \"keep-alive\"
#define CONTENTTYPE \"application/x-www-form-urlencoded\"
#define HOSTNAME \"www.zhibo8.cc\"
#define DEBUG 1
char Request[409600]=\"\";
char Recive[409600]=\"\";
struct hostent *host;
int sockfd=0;
FILE *fp;
struct sockaddr_in server_addr;
int year;
int mon;
int day;
int wday;
int count=0;
void HandLine(char *l);
void SaveResult();
void GetDayInfo();
void GetTime();
int GetLocalAgent(char * UserAgent, char * Accept, char * AcceptLanguage, char * AcceptEncoding, char * AcceptCharset, char * KeepAlive, char * Connection, char * ContentType)
{
memcpy(UserAgent, USERAGENT, strlen(USERAGENT));
memcpy(Accept, ACCEPT, strlen(ACCEPT));
memcpy(AcceptLanguage, ACCEPTLANGUAGE, strlen(ACCEPTLANGUAGE));
memcpy(AcceptEncoding, ACCEPTENCODING, strlen(ACCEPTENCODING));
memcpy(AcceptCharset, ACCEPTCHARSET, strlen(ACCEPTCHARSET));
memcpy(KeepAlive, KEEPALIVE, strlen(KEEPALIVE));
memcpy(Connection, CONNECTION, strlen(CONNECTION));
memcpy(ContentType, CONTENTTYPE, strlen(CONTENTTYPE));
return 0;
}
void CreatRequest()
{
char UserAgent[1024] = \"\", Accept[1024] = \"\", AcceptLanguage[1024] = \"\", AcceptEncoding[1024] = \"\", AcceptCharset[1024] = \"\", KeepAlive[1024] = \"\", Connection[1024] = \"\", ContentType[1024] = \"\";
if((host=gethostbyname(\"www.zhibo8.cc\"))==NULL) /* get ip address by domain */
{
if(DEBUG) fprintf(stderr,\"\\tGethostname \'%s\' error, %s\\n\", HOSTNAME, strerror(errno));
exit(1);
}
GetLocalAgent(UserAgent, Accept, AcceptLanguage, AcceptEncoding, AcceptCharset, KeepAlive, Connection, ContentType); /* Get client browser information */
sprintf(Request, \"GET /%s/%s HTTP/1.0\\r\\nHost: %s\\r\\nUser-Agent: %s\\r\\nAccept: %s\\r\\nConnection: %s\\r\\n\\r\\n\", \"/\", \"\", HOSTNAME, UserAgent, Accept, Connection);
}
本文地址:https://www.stayed.cn/item/3997
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我