抱歉,不能将其写为注释,因为必须包含输出。我正在尝试使用您的代码,当我更改 host 和 wireshark-labs 部分时......发生了一件奇怪的事情。我把它改成
s.sendall(b"GET / HTTP/1.1\r\nHost: www.cnn.com\r\n\r\n") 了解这是如何工作的......
我得到的回应是......
Creation successful
Connection successful
Connected to 128.119.245.12
Data received
HTTP/1.1 200 OK
Date: Mon, 23 Nov 2020 07:48:51 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.12 mod_perl/2.0.11 Perl/v5.16.3
Last-Modified: Tue, 01 Mar 2016 18:57:50 GMT
ETag: "a5b-52d015789ee9e"
Accept-Ranges: bytes
Content-Length: 2651
Content-Type: text/html; charset=UTF-8
<html>
<head>
<title>Computer Network Research Group - UMass Amherst
</title>
</head>
<body bgcolor="#ffffff">
<center>
<p><img
src="cnrg_imap.jpg"
border="0" usemap="#cnrg_imapMAP">
<map name="cnrg_imapMAP">
<area coords="290,177,407,205" shape="rect" href="/networks/resources/index.html">
<area coords="163,178,275,205" shape="rect" href="/networks/education/index.html">
<area coords="62,165,145,191" shape="rect" href="/search.html">
<area coords="6,63,157,90" shape="rect" href="/networks/collaborations.html">
<area coords="64,7,146,34" shape="rect" href="/networks/people.html">
<area coords="163,7,270,33" shape="rect" href="/networks/research.html">
<area coords="288,6,417,33" shape="rect"
href="/networks/
Data received
publications.html">
</map>
<P>
<BR>
<BR>
<P>
<table width=100% border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=60> </td>
<td width="10%"> </td>
<td width="70%">
<font face="Helvetica,Arial,TimesNewRoman" color="#000000">
<h4>
The <a href="/index.html"> Computer Networks Research Group </a> in the <a href = "https://www.cics.umass.edu/"> School of Information and Computer Sciences</a> at
the <a href = "http://www.umass.edu/"> University of Massachusetts, Amherst </a> is led by Professors <a href = "http://www-net.cs.umass.edu/kurose/index.html">Jim Kurose </a>, and <a href = "/personnel/towsley.html">Don Towsley</a>.
Our research spans a broad range of topics in networking, including network protocols and architecture, modeling and analysis, sensor networks, wireless networks, and network measurement. We seek a principled understanding of new and emerging areas through a complementary mix of theoretical and applied experimental research.
</td>
<td width="10%"> </td>
</
Data received
tr>
</table>
</h4>
</font>
<p>
<!-- QUP Button & QualNet link markup start -->
<a href="http://www.scalable-networks.com/customers/qup/index.php">
<img src="http://www.scalable-networks.com/images/qupmember.gif" border=0
alt="QualNet Network Simulator University Program"></a>
<a href="http://www.scalable-networks.com">QualNet Network Simulator</a>
<!-- End of QUP Button HTML & QualNet link markup -->
<p>
<p>
<center>
<font size="1">
<a href="/networks/people.html"> PEOPLE |</a>
<a href="/networks/research.html"> RESEARCH |</a>
<a href="http://www-net.cs.umass.edu/networks/publications.html"> PUBLICATIONS |</a>
<a href="/networks/collaborations.html"> COLLABORATIONS |</a>
<a href="http://gaia.cs.umass.edu/search.html"> SEARCH |</a>
<a href="/networks/education/index.html"> EDUCATION |</a>
<a href="/networks/resources/index.html">
RESOURCES</a>
<p>
</font>
</center>
</body>
</html>
Data received
No Data
Process finished with exit code 0
您正在寻找什么。似乎sendall 命令中的host 值在某处被覆盖。不知道wireshark-labs 部分有多少。希望信息有所帮助。此外,当我将您的代码粘贴到 pycharm 中时,它会在此处发出警告 s.connect((ip, port)) s could be undefined。
P.S:- 我不是socket 编程方面的专家。如有错误请见谅。只是想帮忙。