[asp.net tutorial] one. Web Basics

Source: Internet
Author: User
Tags header html form http request resource client port number
asp.net|web| Tutorial Note: This tutorial is based on the. NET Framework 1.1, uses the C # language description, and assumes that the reader understands the HTML and C # syntax, JScript client script, and understands the basic IIS configuration. These are outside the scope of this tutorial, please refer to the relevant books or tutorials.

1. HTTP protocol

In addition to the TCP/IP protocol, HTTP can be said to be the most important and most widely used network protocol. This section briefly describes how the HTTP protocol works.

Suppose you now have an HTML file: http.html, stored on a Web server, with a URL of www.myweb.com/http.html, and the contents of the file:

HTML Code:

<title>http.html</title>
<body>
Hello, http
</body>

Now, a user accesses the address through IE, ie first converts the domain name of this address through DNS to an IP address, and then opens the port via a Web server (default 80, not 80, after the domain name plus ": Port number", such as www.myweb.com:81) with its connection, Then send an HTTP request like this (you can see similar information in the details when downloading files using download software such as FlashGet):

Code:

Get/http.html http/1.1
Host:www.myweb.com
Accept: */*
user-agent:mozilla/4.0 (compatible; msie.6.0; Windows NT 5.1)
Pragma:no-cache
Cache-control:no-cache
Connection:close
[Blank line]

The request's first behavior request content, which means to request a resource from the server through a Get method,/http.html for the requested resource name, and http/1.1 for the HTTP protocol, version 1.1. The next few lines are referred to as headers for the request information, which describes some of the additional information requested, such as the client browser identity. The last empty line indicates the end of the request.

When the Web server receives the request, the server checks to see if the requested resource is valid and has the appropriate permissions. If there is no problem, the server returns an HTTP response message similar to the following:

Code:

http/1.1 OK
server:microsoft-iis/5.0
Date:thursday, March, 17:15:23 GMT
Content-type:text/html
content-length:88
[Blank line]
<title>http.html</title>
<body>
Hello, http
</body>


The first line of "200" is a status code that indicates that the server successfully completed the request and returned another status code if unsuccessful. Content-type represents the data type returned, Content-length represents the length of the data returned. A blank line represents the end of the header, and the following is the data content that the browser returns based on the request, here is the http.html file content, the browser parses the HTML source code, renders the Web page to the user, and completes a successful HTTP communication here.

The above is the basis of web communication, like the Windows Messaging mechanism, you may not use it, but you have to understand it, and you need to know what low-level content is hidden by those advanced things, which can be very helpful for you to understand and use those advanced things:
2. HTML form

The previous http.html file is one of the simplest static HTML pages, but as a Web application it is simply too primitive to accept user input and always display the same content. We need to be able to return the corresponding data based on user input.

Look at the following HTML code:


HTML Code:
<title>form.html</title>
<body>
<form method= "Get" >
<input type= "text" Name= "P"/>
<input type= "Submit" value= "Submit"/>
</form>
</body>


Look at this code, which has an HTML form, which includes a Submit button (<input type= "Submit" value= "submit"/>) between <form> and </form>, When the user clicks the button, the browser submits all input from the HTML form to the Web server, and the method property of the form label specifies the way the submission is made, here for GET, which corresponds to the GET request methods in the HTTP request, The input in the form is appended to the URL in the form of a query string, a string in the text box, such as "form," and then the browser's address bar, which becomes similar to Http://www.myweb.com/form.html?p=form, This is because the browser issued such a GET request:


Code:
Get/form.html?p=form http/1.1
...
...
[Blank line]


If the <form> label's method attribute is "post", even if the browser sends the request using post, when the Post method is used, the user's input is not transmitted through the URL. Instead, the browser sends the content to the Web server after it has been placed on the header of the POST request:

Code:
Post/form.html http/1.1
...
...
content-type:application/x-www-form-urlencoded
Content-length:6
[Blank line]
P=form

The Web server can then process user input by accessing the data sent by the POST request.

The browser sends user input to the Web server using a Get or post method, a process known as postback (postback). This concept is quite important, and often involves postbacks in web applications.


Related Article

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.