Tiny Web Server tiny web server exercise

Source: Internet
Author: User

Use the WEB programming code in the deep understanding of computer components to understand the principles of HTTP, HTML, and CGI

**************************************** * ****** <Br/> Telnet <br/> ************************* * ******************* <br/> vadmin @ vadmin: ~ $ Telnet localhost 1000 <br/> trying: 1... <br/> trying 127.0.0.1... <br/> connected to localhost. <br/> escape character is '^]'. <br/> Get/HTTP/1.1 </P> <p> HTTP/1.0 200 OK <br/> server: tiny web server <br/> Content-Length: 112 <br/> Content-Type: text/html </P> <p> <HTML> <br/> <pead> <br/> <title> Google </title> <br/> </pead> <br/> <body> <br/> <p> Hi, <p> This is the <B> home.html </B> file. <br/> </body> <br/> </p TML> <br/> Connection closed by foreign host. <br/> vadmin @ vadmin :~ $ </P> <p> ******************************** * ********** <br/> server <br/> ******************** * ********************* <br/> ^ C <br/> root @ vadmin: /home/vadmin/York/code/netp/tiny #. /tiny 1000 <br/> *** Buf: <br/> Get/HTTP/1.1 <br/> end of BUF *** <br/> *** method: get; Uri:/; version: HTTP/1.1 ***** <br/> **************************** <br/> *** HDRs: </P> <p> end of HDRs ***** <br/> *********************** * ***** <br/> URI: /; filename :. /home.html; cgiargs :. <br/> *** HTTP Response heders: <br/> HTTP/1.0 200 OK <br/> server: tiny web server <br/> Content-Length: 112 <br/> Content-Type: text/html </P> <p> end response *** <br/> *** file: <br/> <HTML> <br/> <pead> <br/> <title> Google </title> <br/> </pead> <br/> <body> <br/> <p> Hi, <p> This is the <B> home.html </B> file. <br/> </body> <br/> </ptml> <br/> end of file *** </P> <p>

Use telnet to log on to the server and directly send HTTP requests

Get, HTTP, 1.1

 

The following is an empty line, indicating that the HTTP Request Header ends.

Request URI is/, response is get, request home.html

Server will respond to HTTP Response Header

HTTP/1.0 200 OK
Server: Tiny Web Server
Content-Length: 112
Content-Type: text/html

 

The last blank line indicates that the HTTP Response Header ends,

First, the version is displayed, and then the status code 200 indicates that the version is successful.

Then there are some other HTTP response headers.

The last empty line indicates that the HTTP Response Header ends.

 

Next is the HTTP response body, which is an HTML file.

<HTML>
<Head>
<Title> Google </title>
</Head>
<Body>
<P> Hi, <p> This is the <B> home.html </B> file.
</Body>
</Html>

If you use a browser, you can display the content on the webpage,

For example, enter

Http: // localhost: 1000/

The browser will send the above

Get, HTTP, 1.1

The following is the same. Finally, the server sends the HTML file, and the browser parses the HTML file and displays it.

 

As you can see, you can write a simple browser ~~~~

 

Of course, you can also request some images or something.

For example

GET/logo.gif HTTP/1.1

Of course, you must have this file under the server directory. Otherwise, an error will be reported.

404, not find

 

You can also request dynamic content, such

**************************************** * ****** <Br/> Telnet <br/> ************************ * ********************* <br/> vadmin @ vadmin: ~ $ Telnet localhost 1000 <br/> trying: 1... <br/> trying 127.0.0.1... <br/> connected to localhost. <br/> escape character is '^]'. <br/> Get/cgi-bin/adder? 1 & 3 HTTP/1.1 </P> <p> HTTP/1.0 200 OK <br/> server: tiny web server <br/> Content-Length: 105 <br/> Content-Type: text/html </P> <p> welcome to add.com: the Internet addition portal. <br/> <p> the answer is: 1 + 3 = 4 <br/> <p> thanks for visiting! <Br/> Connection closed by foreign host. <br/> vadmin @ vadmin :~ $ </P> <p> ******************************** * ************* <br/> server <br/> **************** * **************************** <br/> root @ vadmin: /home/vadmin/York/code/netp/tiny #. /tiny 1000 <br/> *** Buf: <br/> Get/cgi-bin/adder? 1 & 3 HTTP/1.1 <br/> end of BUF *** <br/> *** method: Get; Uri:/cgi-bin/adder? 1 & 3; version: HTTP/1.1 ***** <br/> **************************** <br/> *** HDRs: </P> <p> end of HDRs ***** <br/> *********************** * ***** <br/> URI: /cgi-bin/adder; filename :. /cgi-bin/adder; cgiargs: 1 & 3. <br/> *** HTTP Response Header: <br/> HTTP/1.0 200 OK <br/> Server: tiny web server <br/> end of HTTP Response Header *** <br/>

GET/cgi-bin/adder? 1 & 3 HTTP/1.1

The server will read the parameters and obtain the results, and send them to the HTML file through HTTP.

The parameter format is app? Var1 & var2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.