Switch to full style
HTML,DHTML,Javascript,XML,CSS
Post a reply

HTTP POST msg connection close problem

Mon Jan 19, 2009 6:17 am

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.

Appriciate your time and advise on this.

Thanks

The c++ code snipet given below FYR...

{
sprintf(request,"POST /app-srv/read HTTP/1.1\r\nHost: 101.1.1.2:8080\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070718 Red Hat/1.5.0.12-3.el5 Firefox/1.5.0.12\r\nAccept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip,deflate\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 300\r\nConnection: keep-alive\r\nReferer: http://101.1.1.2:8080/app-srv/\r\ntreemenu=none open\r\n");

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);
}

//Set Socket option
if(setsockopt(sd, SOL_SOCKET,SO_KEEPALIVE,(const char*)&reuseFlag, sizeof reuseFlag) <0)
{
perror("set sockopt");
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

if (send(sd, request, strlen(request), 0) != strlen(request)) {
perror("send");
exit(1);
}

l=recv(sd,dir,DIRSIZE,0);
if ( l== -1) {
//done=1;
perror("recv");
exit(1);
}
/* spew-out the results and bail out of here! */

close(sd);
}



Post a reply
  Related Posts  to : HTTP POST msg connection close problem
 Get value from HTTP POST VARS     -  
 Using java in http connection     -  
 How to open http connection using j2me     -  
 database connection pooling problem     -  
 Close a file in php     -  
 Close database connections in php     -  
 open/close new window using javascript     -  
 Send parameters using HTTP GET     -  
 http proxy code     -  
 HTTP Server in Java     -