⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http_parse.c~

📁 实现了一个简单的web服务器
💻 C~
字号:
#include <stdlib.h>#include "server.h"void parse(char *buf,HTTP_REQ *http_req) {  	char *tmp;	char *http_header;//包括文件名和参数	char *params;//所有参数	char *arg;	char *value;	char *type;	int i=0;	int no_param=0;	memset(http_req,'\0',sizeof(http_req));	http_header = buf + 5;  	tmp = strstr(http_header, " HTTP");  	if (tmp != NULL) 		*tmp='\0';	if (DEBUG) 		printf("http header: %s\n", http_header);	tmp=strstr(http_header,"?");	if(tmp!=NULL) {		printf("tmp %s\n",tmp);		*tmp='\0';		params=tmp+1;	}	else {		no_param=1;	}      tmp=strstr(http_header,".");	if(tmp!=NULL) {		printf("tmp %s\n",tmp);		*tmp='\0';		type=tmp+1;	}	strcpy(http_req->req_url,http_header);      strcpy(http_req->req_type,type);	if (DEBUG) {		printf("http header URL: %s\n", http_req->req_url);		printf("http header type: %s\n", http_req->req_type);		if(!no_param) printf("params %s\n",params);	} 	if(!no_param) {		// 提取各参数		i=0;		do {			arg=params;			tmp=strstr(params,"&");			if(tmp==NULL) {				tmp=strstr(arg,"=");				if(tmp!=NULL) {					*tmp='\0';					value=tmp+1;					strcpy(http_req->params[i].name,arg);					if (DEBUG) 						printf("http header param name: %s\n", http_req->params[i].name); 				 	strcpy(http_req->params[i].value,value);					if (DEBUG) 						printf("http header param value: %s\n", http_req->params[i].value);					http_req->param_count=i+1;					break;				}			}			else if(tmp!=NULL) {				*tmp='\0';				params=tmp+1;				tmp=strstr(arg,"=");				if(tmp!=NULL) {					*tmp='\0';					value=tmp+1;					strcpy(http_req->params[i].name,arg);					if (DEBUG) 						printf("http header param name: %s\n", http_req->params[i].name); 				 	strcpy(http_req->params[i].value,value);					if (DEBUG) 						printf("http header param value: %s\n", http_req->params[i].value);					i++;				}			}		}while(i<MAX_PARAMS);	}	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -