..


Sponsored Links

The HTTP protocol (in the environment. NET)

The mechanism by which the various browsers communicate with web sites, as previously mentioned, is based on a protocol called Hypertext Transfer Protocol (HTTP).
In its original form this protocol is designed for transferring hypertext documents, or documents linked together but without a well-defined user interface, but what is the strength of modern web applications.

HTTP is a protocol that is based on some basic commands. The most important of them are GET and POST, but others are important controls such as HEAD and PUT. The GET method returns the information that is identified by 'Uniform Resource Identifier (URI) specified by the request (basically the address of the website). The POST method is used to send a request to the web server. The HEAD command returns only the header information identified by the URI of the request. The PUT method is used to send information to the server but in the form of documents and records instead of parameters.

The objective of this lesson is not to deepen the knowledge of HTTP, but to explain how it is rooted in the environment. NET development. This environment includes several classes that allow it to make HTTP requests. The WebRequest class, for example, includes a method called GetResponse, which sends a request to a specific address.

To see how to make a direct request to a web server without a browser implement a small sample program. We start Visual Studio and create a new project by choosing New Project dialog box, the type of Console Application project

Let's add the newly generated program code to make requests to the web. Visual Studio creates the application as a starting point for a file named Program.cs.

Inside that file add the following code:






 using System; using System.Collections.Generic;

 





 using System.Linq;







 using System.Text;







 using System.Net;







 using System.IO;









 namespace WebRequestorApp







 {

 

  



 class Program {



    



 static void Main (string [] args) {

 

      



 WebRequest req = WebRequest.Create ("http://www.google.com");

 

      



 WebResponse resp = req.GetResponse ();

 

      



 StreamReader reader = new StreamReader (resp.GetResponseStream (), Encoding.ASCII) Console.WriteLine (reader.ReadToEnd ());

 

    



 }



  



 }







 }



We start the application by clicking Start Without Debugging from the menu after a while we'll see Debugging and HTML code on our screen. Clearly seen in this way the HTML is not easily understood and its interpretation is limited to browsers that have the task of sending requests to the web server and receive an answer, making it understandable to users. This example only serves to show the basic features of a web request.

The work basically consists of a browser to create and send a request to a web server (via the corresponding URL) and receiving the response, submitting the same in a form understandable to users. The answer usually consists of a stream (stream) of text containing HTML tags.

Developing ASP.NET applications we'll have to do very often with HTML. Most of this code is generated automatically by the server side controls (server-side controls) but in some cases, we will ourselves to having to write HTML code to customize our pages or to create a custom control according to your needs.

For example the following code generates a HTML page containing a button and a drop-down menu:






 <html>

 





 <body>

 





 <h2> Hello there.

 



 What's your favorite. NET Feature </ h2>

 





 <select name='Feature'>







 <option> Type-Safety </ option>

 





 <option> garbage collection </ option>

 





 Multiple Syntaxes <option> </ option>

 





 <option> Code Access Security </ option>

 





 <option> Simpler Threading </ option>

 





 Versioning <option> purgatory </ option>

 





 </ Select> <br/>

 





 <input type=submit name='Lookup' value='Lookup'> </ input>

 





 <br/>

 





 </ Body>







 </ Html>



It is a static page that allows you to select a value, and only works locally.

Help with Visual Studio ASP.Net
E-Learning
ASP (Advanced) ASP (Advanced)
Full course for creating dynamic Web sites. From 39 €.
ASP.NET (Course) ASP.NET (Course)
Full course for building Web applications from 49 €.
SQL and Database (Course) SQL and Database (Course)
Create and manage relational databases. From 39 €.
Sponsored Links