我们平时对 telnet 用的最多的应该是 telnet 来快速测试服务端口是否可用,其实 telnet 还可以被用来发送 HTTP 请求,是的,没听错,发送 HTTP 请求!
1.首先启动一个 web server:
root@robert-Ubuntu:/media/sf_WorkSpace/HelloNG/src/testcode/djangoTest/robappdj# python manage.py runserver 0.0.0.0:8082
------In the manage.py, To test: this sentence will be output how many times------
---robert--BASE_DIR = /media/sf_WorkSpace/HelloNG/src/testcode/djangoTest/robappdj---
------In the manage.py, To test: this sentence will be output how many times------
---robert--BASE_DIR = /media/sf_WorkSpace/HelloNG/src/testcode/djangoTest/robappdj---
Performing system checks...
DEBUG 2020-08-13 18:56:25,274 utils 18546 140029887874816 (0.001) SET SQL_AUTO_IS_NULL = 0; args=None
System check identified no issues (0 silenced).
DEBUG 2020-08-13 18:56:25,842 utils 18546 140029887874816 (0.000) SET SQL_AUTO_IS_NULL = 0; args=None
DEBUG 2020-08-13 18:56:25,849 utils 18546 140029887874816 (0.006) SHOW FULL TABLES; args=None
DEBUG 2020-08-13 18:56:25,855 utils 18546 140029887874816 (0.002) SELECT `django_migrations`.`app`, `django_migrations`.`name` FROM `django_migrations`; args=()
August 13, 2020 - 18:56:25
Django version 1.8.7, using settings 'robappdj.settings'
Starting development server at http://0.0.0.0:8082/
Quit the server with CONTROL-C.
In the hellooooooo
---To get what the request has---------
type(request) =
{'LC_NUMERIC': 'zh_CN.UTF-8', 'RUN_MAIN': 'true', 'SERVER_PROTOCOL': 'HTTP/1.0', 'SERVER_SOFTWARE': 'WSGIServer/0.1 Python/2.7.12', 'SCRIPT_NAME': u'', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'QUERY_STRING': '', 'SSH_CLIENT': '192.168.56.1 62540 22', 'REQUEST_METHOD': 'GET', 'LOGNAME': 'root', 'USER': 'root', 'HOME': '/root', 'LC_PAPER': 'zh_CN.UTF-8', 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin', 'wsgi.multithread': True, 'LANG': 'en_US.UTF-8', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'TZ': 'Asia/Shanghai', 'SERVER_NAME': 'robert-Ubuntu', 'REMOTE_ADDR': '192.168.56.101', 'LC_MEASUREMENT': 'zh_CN.UTF-8', 'QT_QPA_PLATFORMTHEME': 'appmenu-qt5', 'wsgi.url_scheme': 'http', 'SERVER_PORT': '8082', 'CONTENT_LENGTH': '', 'XDG_RUNTIME_DIR': '/run/user/0', 'wsgi.file_wrapper': , 'LC_ADDRESS': 'zh_CN.UTF-8', 'SHLVL': '1', 'wsgi.input': , 'HTTP_HOST': '192.168.56.101:8082', 'XDG_DATA_DIRS': '/usr/local/share:/usr/share:/var/lib/snapd/desktop', 'wsgi.version': (1, 0), 'XDG_SESSION_ID': '3', '_': '/usr/bin/python', 'LC_IDENTIFICATION': 'zh_CN.UTF-8', 'SSH_CONNECTION': '192.168.56.1 62540 192.168.56.101 22', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'GATEWAY_INTERFACE': 'CGI/1.1', 'wsgi.run_once': False, 'SSH_TTY': '/dev/pts/8', 'OLDPWD': '/root', 'wsgi.multiprocess': False, 'LC_TELEPHONE': 'zh_CN.UTF-8', 'LC_MONETARY': 'zh_CN.UTF-8', 'PWD': '/media/sf_WorkSpace/HelloNG/src/testcode/djangoTest/robappdj', 'DJANGO_SETTINGS_MODULE': 'robappdj.settings', 'CONTENT_TYPE': 'text/plain', 'LC_NAME': 'zh_CN.UTF-8', 'MAIL': '/var/mail/root', 'LC_TIME': 'zh_CN.UTF-8', 'LS_COLORS': 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:', 'REMOTE_HOST': '', 'wsgi.errors': ', mode 'w' at 0x7f5b443881e0>, 'PATH_INFO': u'/hello/'}
-------------------------------------
request =
In hello,request.META['CONTENT_TYPE'] = text/plain
In hello,request.META['REMOTE_ADDR'] = 192.168.56.101
request.path = /hello/
request.path_info = /hello/
request.get_full_path() = /hello/
request.build_absolute_uri() = http://192.168.56.101:8082/hello/
-------In hello--------------
request.user = AnonymousUser
type(request.user) =
request.session =
type(request.session) =
request.COOKIES = {}
---------misc--------------
DEBUG 2020-08-13 18:56:46,916 utils 18546 140029877049088 (0.001) SET SQL_AUTO_IS_NULL = 0; args=None
DEBUG 2020-08-13 18:56:46,955 utils 18546 140029877049088 (0.036) INSERT INTO `TestModel_test` (`name`) VALUES (''); args=[u'']
In the post_save callback111: sender = , kwargs = {'update_fields': None, 'instance': , 'signal': , 'created': True, 'raw': False, 'using': 'default'}
In the POST tmp = None
[13/Aug/2020 18:56:47] "GET /hello/ HTTP/1.0" 200 199
^Croot@robert-Ubuntu:/media/sf_WorkSpace/HelloNG/src/testcode/djangoTest/robappdj#
telnet 登录 上述服务端口,我只需输入:
GET /hello/ HTTP/1.0
Host: 192.168.56.101:8082
然后加回车即可
root@robert-Ubuntu:/tmp# telnet 192.168.56.101 8082
Trying 192.168.56.101...
Connected to 192.168.56.101.
Escape character is '^]'.
GET /hello/ HTTP/1.0
Host: 192.168.56.101:8082
HTTP/1.0 200 OK
Date: Thu, 13 Aug 2020 10:56:47 GMT
Server: WSGIServer/0.1 Python/2.7.12
Vary: Cookie
X-Frame-Options: SAMEORIGIN
Content-Type: text/html; charset=utf-8
Title
Hello ===AnonymousUser === !
The path info of http request is /hello/
Connection closed by foreign host.
root@robert-Ubuntu:/tmp#
root@robert-Ubuntu:/tmp#