Here is my code:
struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(80); char* ip = "151.101.129.69"; //ru.stackoverflow.com addr.sin_addr.s_addr = htonl(ip2int(ip)); int sockRequest = socket(AF_INET, SOCK_STREAM , 0); if(sockRequest == -1)exit(2); char* request = "GET HTTP/1.1\r\nHost: ru.stackoverflow.com\r\n\r\n"; printf("%s\r\n", request); write(sockRequest, request, strlen(request)); char buff[1024]; int count = read(sockRequest, buff, 1024); write(1, buff, count + 1); write(1, "\r\n", 1); close(sockRequest); Postman with this request
GET HTTP/1.1 Host: ru.stackoverflow.com gives the html content of the site, and my program gives the error 400 "Bad request" .
What's wrong?
GET / HTTP/1.1. - Ainar-GBad requestonGET HTTP/1.1, but onGET / HTTP/1.1-HTTP/1.1 301 Moved Permanently...Location: https://ru.stackoverflow.com/, and in the response body -<h2>Object moved to <a href="https://ru.stackoverflow.com/">here</a>. </h2><h2>Object moved to <a href="https://ru.stackoverflow.com/">here</a>. </h2>. Probably Postman correctly handles the https protocol forwarding. - avp pm