Understanding URLs and Making Web Requests
????? ?????????? ?
15?? ?????????????????? ||?????????????? || ??????????||?????????? ?????? || ???? || ???????????????????? ||??&?? || ??????|| ?????????? ???????????????? ||????????#?????????????????? || ?????????????? ????????????
Accessing a Website and Understanding URLs
When you access a website, your browser sends requests to a web server to retrieve resources such as HTML files, images, and other assets. Before making these requests, the browser needs to know exactly how and where to find these resources. This is where URLs (Uniform Resource Locators) come into play.
What is a?URL?
If you’ve used the internet, you’ve interacted with URLs. A URL is essentially a set of instructions that tells your browser how to access a resource on the internet. Below, we’ll break down the components of a URL and explain their functions:
URL Structure Diagram
? Scheme: https:// ? User: user:password@ ? Host: Techclick.in’ ? Port: :80` ? Path: /view-room ? Query String: ?id=1 ? Fragment: #task3
Example URL: https://user:[email protected]:80/view-room?id=1#task3
Components of a?URL
? Scheme: This part of the URL tells the browser which protocol to use when accessing the resource. Common schemes include HTTP, HTTPS, and FTP.
? User: Some services require authentication. The user section allows you to include a username and password directly within the URL for logging in.
? Host: The host is the domain name (like example.com) or IP address of the server you want to access.
? Port: This specifies the port number on the server to which the browser should connect. Standard ports include 80 for HTTP and 443 for HTTPS, though any port between 1 and 65535 can be specified.
? Path: The path indicates the specific file or resource location on the server that you wish to access.
? Query String: This part of the URL allows you to send additional parameters to the requested resource. For example, in /blog?id=1, the id=1 part might tell the server that you want to view the blog post with an ID of 1.
? Fragment: This is a reference to a specific section of the page. It’s useful for directing users to a particular part of a web page, especially on long pages.
领英推荐
Making a?Request
When you request a web page, you typically do so with a simple line like:
GET / HTTP/1.1 However, for a richer web experience, additional data is sent along with the request in the form of headers. Headers contain extra information that your browser sends to the web server to enhance the communication process.
Example Request:
GET / HTTP/1.1 Host: techclick.in User-Agent: Mozilla/5.0 Firefox/87.0 Referer: https://example.com/
Understanding HTTP Methods
Common HTTP?Methods
GET Request
? Purpose: Used for retrieving information from a web server.
? Usage: When you enter a URL in your browser, a GET request is made to fetch the web page or resource from the server.
POST Request
? Purpose: Used for submitting data to a web server, which may result in creating a new record or resource.
? Usage: Often used when submitting form data, such as a registration form or a login form on a website.
PUT Request
? Purpose: Used for submitting data to a web server to update existing information or resources.
? Usage: Commonly used in RESTful APIs when updating an existing resource like editing a user profile.
DELETE Request