Example #1
0
File: test.c Project: nexa/se
int main(int argc, char **argv)
{
  http_t me;
  int res;
  char *keys[] = {sz1, sz2};



 
  http_init(&me, keys, 2);
 

  http_hypertext_attach(&me, ht);
  http_hypertext_receving(&me, strlen(ht));

  res = http_parse_result(&me);

  /*  http_hypertext_detach(&me);*/



  hdr_parser_compile(&me);

  me.hdr_parser_current = me.hdr_parser_root;

  http_parse_hdr(&me);

  hdr_parser_dismiss(&me);
  http_uninit(&me);

  exit(0);
}
Example #2
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);  
}  
Example #3
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);  
}