Ejemplo n.º 1
0
char * http_get(const char *url,int timeout)  
{  

	char post[BUFFER_SIZE] = {'\0'};  
	int socket_fd = -1;  
	char lpbuf[BUFFER_SIZE*4] = {'\0'};  
	char *ptmp;  
	char host_addr[BUFFER_SIZE] = {'\0'};  
	char file[BUFFER_SIZE] = {'\0'};  
	int port = 0;  
	int len=0;  

	if(!url){  
		printf(NET_LIB_TAG"      failed!\n");  
		return NULL;  
	}  

	if(http_parse_url(url,host_addr,file,&port)){  
		printf(NET_LIB_TAG"http_parse_url failed!\n");  
		return NULL;  
	}  
	//printf(NET_LIB_TAG"host_addr : %s\tfile:%s\t,%d\n",host_addr,file,port);  

	socket_fd =  http_tcpclient_create(host_addr,port,timeout);  
	if(socket_fd < 0){  
		printf(NET_LIB_TAG"http_tcpclient_create failed\n");  
		return NULL;  
	}  

	sprintf(lpbuf,HTTP_GET,file,host_addr,port);  

	if(http_tcpclient_send(socket_fd,lpbuf,strlen(lpbuf),timeout) < 0){  
		printf(NET_LIB_TAG"http_tcpclient_send failed..\n");  
		return NULL;  
	}  
	//printf(NET_LIB_TAG"GET Sent:\n%s\n",lpbuf);  
	memset(lpbuf,0,BUFFER_SIZE*4);
	if((len=http_tcpclient_recv(socket_fd,lpbuf,timeout)) <= 0){  
		printf(NET_LIB_TAG"http_tcpclient_recv failed\n");  
		return NULL;  
	}
	else
	{
		http_tcpclient_recv(socket_fd,lpbuf+len,3);
	}
	http_tcpclient_close(socket_fd);  

	return http_parse_result(lpbuf);  
}  
Ejemplo n.º 2
0
char * http_post(const char *url,const char *post_str,int timeout){  

	char post[BUFFER_SIZE] = {'\0'};  
	int socket_fd = -1;  
	char lpbuf[BUFFER_SIZE*4] = {'\0'};  
	char *ptmp;  
	char host_addr[BUFFER_SIZE] = {'\0'};  
	char file[BUFFER_SIZE] = {'\0'};  
	int port = 0;  
	int len=0;  
	char *response = NULL;  

	if(!url || !post_str){  
		printf(NET_LIB_TAG"      failed!\n");  
		return NULL;  
	}  

	if(http_parse_url(url,host_addr,file,&port)){  
		printf(NET_LIB_TAG"http_parse_url failed!\n");  
		return NULL;  
	}  
	//printf(NET_LIB_TAG"host_addr : %s\tfile:%s\t,%d\n",host_addr,file,port);  

	socket_fd = http_tcpclient_create(host_addr,port,timeout);  
	if(socket_fd < 0){  
		printf(NET_LIB_TAG"http_tcpclient_create failed\n");  
		return NULL;  
	}  

	sprintf(lpbuf,HTTP_POST,file,host_addr,port,(int)strlen(post_str),post_str);  

	if(http_tcpclient_send(socket_fd,lpbuf,strlen(lpbuf),timeout) < 0){  
		printf(NET_LIB_TAG"http_tcpclient_send failed..\n");  
		return NULL;  
	}  
	//printf(NET_LIB_TAG"POST Sent:\n%s\n",lpbuf);  
	memset(lpbuf,0,BUFFER_SIZE*4);
	/*it's time to recv from server*/  
	if((len=http_tcpclient_recv(socket_fd,lpbuf,timeout)) <= 0){  
		printf(NET_LIB_TAG"http_tcpclient_recv failed\n");  
		return NULL;  
	}
	
//	http_tcpclient_recv(socket_fd,lpbuf+len,timeout);
	
	http_tcpclient_close(socket_fd);  

	return http_parse_result(lpbuf);  
}  
Ejemplo n.º 3
0
int handle_connect(int varNum)
{
	char *pResult = NULL;
	char host_addr[BUFFER_SIZE] = {'\0'};
	char file[BUFFER_SIZE] = {'\0'};
	// char lpbuf[BUFFER_SIZE * 4] = {'\0'};

	char *lpbuf = calloc(1024, sizeof(char));

	char lpbuf1[BUFFER_SIZE * 4] = {'\0'};
	char lpbuf2[BUFFER_SIZE * 4] = {'\0'};
	char lpbuf3[BUFFER_SIZE * 4] = {'\0'};
	//char *pUrl = "http://wap.dev.epet.com/group/v226/detail.html?do=Login";
	char *pUrl = "http://wap.dev.epet.com/main.html";


	char *pHttpContent = NULL;
	key_value *vals_message_type = NULL;
	int port = 0;
	int socket_fd = -1;
	int flag = -1;
	int cookesNum = 0;
	//char *urlTemplet = "http://wap.dev.epet.com/group/v226/detail.html?do=Login&uid=";

	char *urlTemplet = "http://wap.dev.epet.com/main.html";
	char numCtr[10] = {'\0'};
	sprintf(numCtr, "%d", varNum);
	char *urlStr = NULL;
	urlStr = (char *)calloc((strlen(urlTemplet)), sizeof(char));
	strcat(urlStr, urlTemplet);
	flag = http_parse_url(pUrl, host_addr, file, &port);
	socket_fd = http_tcpclient_create(host_addr, port);
	flag = http_get_send_content(&pResult, urlStr, vals_message_type, cookesNum);


	flag = http_tcpclient_send(socket_fd, pResult);
	free(pResult);
	pResult = NULL;	
	flag = http_tcpclient_recv(socket_fd, &lpbuf);
	printf("lbuff=%s\n", lpbuf);
	free(lpbuf);
	lpbuf = NULL;
	close(socket_fd);
	
	return 1;
}