Http brief introduction

Before using HttpListener wrote as a simple HTTP server, followed by the actual project will use the test found, if not in Win7 under administrator privileges to run the program, will use HttpListener wrong.
So it is curious how a HTTP server is going on. Also take this opportunity to familiarize yourself with the content of the HTTP protocol with TCP is implemented over HTTP client and server, what profile do not write here. Recorded directly about key elements.
HTTP request message format:
request line CRLF
request header CRLF
CRLF
request body

Request line format: the request method URL protocol version
request headers and the request must be added between the main CRLF.
If the POST request, the request need to increase the content of the body, this time must be added to the request header Content-Length information indicating request contents information length of the body.
Simple GET request message contents:
GET / Remote the HTTP / 1.1 \ R & lt \ n-
the Host: localhost: 1205 \ R & lt \ n-
\ R & lt \ n-
the Get Request No Request body, the body of the request is null
simple POST request packet content:
POST / the HTTP / 1.1 \ R & lt \ n-
the Host: localhost: 1205 \ R & lt \ n-
the Content-the Type: file application / X-WWW-form-urlencoded \ R & lt \ n-
the Content-the Length: 22 is \ R & lt \ n-
\ R & lt \ n-
username = Xiao & pwd = ming

As shown in C #:
Get
the HTTP response message format
status line CRLF
response header CRLF
CRLF
response body

Status line format: protocol version Status Code Description
simple response packet:
the HTTP / 1.1 200 is the OK \ R & lt \ n-
the Content-the Length: 22 is \ R & lt \ n-
the Content-the Type: file application / JSON \ R & lt \ n-
\ R & lt \ n-
{ "info ":" Hello World "}
C # in FIG implemented:
response

Guess you like

Origin www.cnblogs.com/zzr-stdio/p/11761190.html