Refer this: rfc2616
10.4.1 400 Bad Request
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
When you are passing:
char msg[] = "CONNECT example.com:80 HTTP/1.0 <CR><LF> HOST example.com:80 <CR><LF> \n";
Then perhaps the <CR>
and <LF>
parts are sent as it is as strings, instead of the ASCII 0xA and 0xD, which represent the control characters you intend to send.
The simplest fix would be using C equivalents: \r
for <CR>
and \n
for <LF>
:
char msg[] = "CONNECT example.com:80 HTTP/1.0 \r\n HOST example.com:80 \r\n\r\n";
If you intend to expand the use of the msg[]
array to contain many more requests you might have to write a wrapper function to translate the CR,LF and other control strings in the msg[]
into appropriate C char equivalents to form proper message.
Hope this helps.