Jump to content

HTTP POST connection close - Problem


Jaishree

Recommended Posts

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

}

 

 

Link to comment
Share on other sites

http://www.phpfreaks.com/forums/index.php/topic,234163.msg1087458.html#msg1087458

 

 

Did you not believe me the first time?

 

 

But, if that's not it, try outputting the stuff that you're sending.  Maybe you're missing a linebreak somewhere or something.

 

 

Thanks Corbin

 

I tried it out since i belived

But it didn't work

I set "KeepAlive: On" & "maxNumberof connection :100"    in httpd.conf

i guess the way proceed was correct

is it so?

 

is there any specific linebreaks that should be given after some bytes in the POST message  ??

 

Thank you

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.