Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Telnet establishes a http connection and obtains the HTML content of the web page

Shulou Source: shulou.com Published: 2022-06-02 05:13:55 11月11日 Update

This article mainly explains "telnet establish http connection and get web HTML content". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "telnet establish http connection and get web HTML content".

Using telnet, you can establish a http connection with the server, obtain the web page, and realize the function of the browser.

It is very convenient for observing and testing http header. Because the browser can't see http header.

The steps are as follows:

Telnet www.csua.berkeley.edu 80

Enter GET / officers.html HTTP/1.0 and enter twice.

At this point you should be able to see http response, including header and body.

Because window itself brings it to telnet that you can't see what you enter when you type it, you can download putty and connect with raw tcp connection.

The things you need to note are as follows:

1. GET and HTTP must be uppercase, because many servers require uppercase, and lowercase will cause connection failure on some servers.

2. For HTTP1.1, you also need to add a line indicating host, which is the requirement of http1.1.

GET / officers.html HTTP/1.1

Host: www.csua.berkeley.ed

Another reason for adding host here is that many websites are in the form of virtual hosts, which are necessary to distinguish host from other virtual hosts on the same host.

3. 2 carriage returns means that the request is sent, because the http request ends with the last blank line.

4. Some of the smarter sites will block http request that is not a browser, so we need to pretend to be a browser and need set's User-agent.

GET / officers.html HTTP/1.1

Host: www.csua.berkeley.ed

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5

5. To grab the package of a http connection, you can use Wireshark to get the browser's http request and response, and then use telnet to simulate the browser to connect.

Thank you for your reading, the above is the content of "telnet establish http connection and get web HTML content". After the study of this article, I believe you have a deeper understanding of the problem of telnet establishing http connection and obtaining web HTML content, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Content browser browsing web page host server learning service input one line uppercase website virtual host smart then things then function reason lowercase Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia Shulou Technology Microsoft Linux