P
Patrick Coleman
Hi,
I have the following code:
char request[] = "GET ";
strcat(request, path); //Path is the path section of a url ie. "/path/test.htm"
strcat(request, " HTTP/1.1");
cout<<request<<"\n"; //This outputs "GET /path/test.htm HTTP/1.1" happily
//Send packet (I know there's no error checking, this is just an example)
int numbytes;
numbytes = send(socknum, request, sizeof(request), 0));
cout<<"Tried to send "<<sizeof(request)<<" bytes, sent "<<numbytes<<" bytes.\n";
//This line outputs 5 bytes Tried, 5 bytes sent, which is my problem
The problem with this is that when I check the packet sent (with a packet
sniffer) the packets only contains "GET " (It should contain
"GET /path/test.htm HTTP/1.1"). It seems to me that only the variable
declaration is storing the data properly, and the strcat command just
'links' that data somehow...(I'm probably wrong, but thats my (vague) idea of the
situation, anyway)
How can I get around this? I know if I declare request of a fixed length,
ie.
char request[1024] = "GET ";
strcat(request, path);
strcat(request, " HTTP/1.1");
It outputs everything, but request is padded with \0 which confuses the
other server even more. Besides, if the path is longer than that, it'll
screw up...
Thanks for any help in advance,
Patrick
I have the following code:
char request[] = "GET ";
strcat(request, path); //Path is the path section of a url ie. "/path/test.htm"
strcat(request, " HTTP/1.1");
cout<<request<<"\n"; //This outputs "GET /path/test.htm HTTP/1.1" happily
//Send packet (I know there's no error checking, this is just an example)
int numbytes;
numbytes = send(socknum, request, sizeof(request), 0));
cout<<"Tried to send "<<sizeof(request)<<" bytes, sent "<<numbytes<<" bytes.\n";
//This line outputs 5 bytes Tried, 5 bytes sent, which is my problem
The problem with this is that when I check the packet sent (with a packet
sniffer) the packets only contains "GET " (It should contain
"GET /path/test.htm HTTP/1.1"). It seems to me that only the variable
declaration is storing the data properly, and the strcat command just
'links' that data somehow...(I'm probably wrong, but thats my (vague) idea of the
situation, anyway)
How can I get around this? I know if I declare request of a fixed length,
ie.
char request[1024] = "GET ";
strcat(request, path);
strcat(request, " HTTP/1.1");
It outputs everything, but request is padded with \0 which confuses the
other server even more. Besides, if the path is longer than that, it'll
screw up...
Thanks for any help in advance,
Patrick