Command-Line

如何從原始數據發出 HTTP 請求?

  • November 22, 2019

我有一些原始格式的 HTTP 請求,例如

GET /docs/index.html HTTP/1.1
Host: www.nowhere123.com
Accept: image/gif, image/jpeg, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
(blank line)

curl由於這個原因,我必須測試和調試它們,我需要一種簡單的方法在我的電腦上重複它們,我如何使用原始數據httpie或其他 CLI HTTP 客戶端發出 HTTP 請求?

我建議 telnet:telnet www.nowhere123.com 80你正在與伺服器交談。

例子:

telnet 127.0.0.1 80

Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

GET /index.htm

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https:///index.htm">here</a>.</p>
</body></html>
Connection closed by foreign host.

引用自:https://unix.stackexchange.com/questions/553552