I am working with a server written in Active State Perl. Apparently, if a GET
request is poorly formed, response results will return, but without their http headers. That is true in my case.
The Perl server listens for requests and send response using IO::Socket
and SendHTTPRequest
respectively.
So my question(s) are as follows. Is the following GET
request invalid?
"GET
?CA=1&STREET=990%20MASS%20AVENUE&STREET2=UNIT%20A37&CITY=ARLINGTON&STATE=MA&ZIP=00000%20HTTP/1.1\r\n\r\n"
If the request is invalid how is it invalid? I would like to correct the format.
Apparently, ActiveState Perl thinks the request is not valid.
After the socket is correctly set up, the following code sends the request and waits for a response. If you need to see the socket setup including the host name, I'll edit this post and add at the bottom, but assume the socket is set up correctly.
size_t bytes_read = 0; /* Keeps per-loop read-count. */
char local_buf[INET_BUF_LEN] = {'\0'};
total_socket_read_bytesM = 0; /* Initialize module-scope read length */
write (socket_fdP, request_bufP, strlen(request_bufP));
while(TRUE)
{
if(total_socket_read_bytesM <= (read_bufP_len - 1))
{
bytes_read = read(socket_fdP, (local_buf + bytes_read), sizeof(local_buf));
if (bytes_read == 0)
{
break;
}
else
{
total_socket_read_bytesM += bytes_read;
}
}
else
{
break;
}
}
I could punt, and not worry given I'm getting results back. However, I would like to write my C program to create a valid http GET
request.
Epilogue:
This is what my working request looks like:
"GET /?CA=1&STREET=990%20MASS%20AVENUE&STREET2=UNIT%20A37&CITY=ARLINGTON&STATE=MA&ZIP=00000 HTTP/1.1\r\n\r\n"