Total members 10262 | Gratitudes |It is currently Thu May 24, 2012 9:49 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: HTTP POST msg connection close problem
PostPosted: Mon Jan 19, 2009 6:17 am 
Offline
Newbie
User avatar

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.

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


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 JavaScript fade out problem
 Bluetooth connection using C# (won't work)
 problem with JcheckBox method
 client server problem
 problem
 Application for the post of Network Admin.
 Matlab SVM training problem
 I have a serious virus/trojan problem, anyone pls?
 database connection
 open/close new window using javascript

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team