Question subject: HTTP POST msg connection close problem
Posted: Mon Jan 19, 2009 6:17 am
Joined: Sat Jan 17, 2009 10:35 am Posts: 2 Has thanked: 0 time Have thanks: 0 time
Problem:
when we are sending HTTP POST request (From C++ Program)- Connection got closed with "Connection reset by peer" mesaage after 5 transfers.
But , when we are doing a POST msg in the web browser, the same message getting accepted by apache. Not sure whether we are doing mistake in setting up the connection or some thing else.
strcpy(hostname,HOST); if (argc>2) { strcpy(hostname,argv[2]); }
/* go find out about the desired host machine */ if ((hp = gethostbyname(hostname)) == 0) { perror("gethostbyname"); exit(1); }
/* fill in the socket structure with host information */ memset(&pin, 0, sizeof(pin)); pin.sin_family = AF_INET; pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; pin.sin_port = htons(PORT);
/* grab an Internet domain socket */ if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); }
/* connect to PORT on HOST */ if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) { perror("connect"); exit(1); }
/* send a message to the server PORT on machine HOST */ if (send(sd, request, strlen(request), 0) != strlen(request)) { perror("send"); exit(1); }
sprintf(request,"Content-Type: application/x-www-form-urlencoded\r\nContent-Length: 11986\r\n?xmlvalues= <test>................</test>"); // Very long - post string of size 11986... Not shown the sting fully in this line