apache - How to make http request and send data another server in APACHE2.2 -
i developing 1 apache plugin fetch data request header , need send data server. tried apr_socket_sento() , apr_socket_create() none of them working . please tell me how send or data server in apache2.2 plug in .
please find ans how send , receive data server.
char* post_data_server_sync(request_rec *r,char *host,char *payload,int timout) { char buffer[1024]; char *hostname=host; char *final_msg; char *msg = "post /getrequestdata http/1.1\r\n"\ "host: %s\r\n" \ "accept: */*\r\n"\ "connection: keep-alive\r\n"\ "content-length: %d\r\n"\ "content-type: application/x-www-form-urlencoded\r\n\n%s"; apr_socket_t *new_sock; apr_sockaddr_t *addr; apr_port_t port_no=80; apr_status_t result; apr_interval_time_t tmout=timout; apr_size_t *size=apr_palloc(r->pool,sizeof(apr_size_t)); apr_size_t *size_rcv=apr_palloc(r->pool,sizeof(apr_size_t)); final_msg=apr_psprintf(r->pool,msg,host,strlen(payload),payload); result=apr_socket_create(& new_sock,apr_inet,sock_stream,apr_proto_tcp,r->pool); result=apr_sockaddr_info_get(&addr,hostname,apr_inet,port_no,0,r->pool); result=apr_socket_connect(new_sock,addr); *size=strlen(final_msg); result=apr_socket_sendto(new_sock,addr,0,final_msg,size); if(result==apr_success) { *size_rcv=sizeof(buffer); result=apr_socket_recvfrom(addr,new_sock,0,buffer,size_rcv); } result=apr_socket_close(new_sock); return buffer; }
Comments
Post a Comment