HTTP Server (C code), Need Help | SoloLearn: Learn to code for FREE!

+1

HTTP Server (C code), Need Help

Hello everyone! I'm trying to create a very simple HTTP server on C. It works, but not fine :) as usual :) On the client machine chrome browser doesn't see index.html But starting to download index.html as a file, without .html As I can see the answer of server , the output is correct. It starting from "HTTP/1.1 200 OK <!DOCTYPE html> and so forth. This is the code: https://code.sololearn.com/c5hF9mBRgWQg UPD: I've just found the mistake! I have to add another "\n" after the header in the server answer. It's the requirements of HTTP 1.1 protocol! So final valid server answer is "HTTP/1.1 200 OK\r\n\n\n" and so forth. BUT I HAVE ANOTHER PROBLEM! How HTPP server sends to the client CSS file and file with javascript (index.html related)? So now my server sends to the client only html body of the page.

7/4/2020 8:11:59 PM

Денис Филь

4 Answers

New Answer

+2

Your server responds to requests. The browser requests a page and the server provides it. The server does not parse the requested file for any related javascript, css, images or anything else. The browser parses the file and makes additional requests to the server for the related files.

+2

I work out this problem. Now server works fine and sends to the client .html, .css, .js and other files with the main page of the website

+1

ACME Labs Software http://www.acme.com/software/ has some interesting open source small http servers available for download. Perhaps you could take a look at their code and learn from it.

+1

OK, browser has received the html page. Parse it. And send the request to server "please 🙏 give me css and js files". Am I right? But it's only string. What text does browser send when it requests the file with css? And what text of server answer on this request?