获取对 HTTPS GET 请求的原始、未解析的响应

发布于 2024-12-27 21:09:41 字数 114 浏览 0 评论 0原文

您将如何获得对 HTTPS 请求的完全未解析的响应?

是否有任何 HTTP 库可以让您获取原始响应,或者使用套接字手动构造请求是唯一的方法吗?

我特别想看看服务器正在发送哪些换行符。

How would you go about getting a completely unparsed response to a HTTPS request?

Are there any HTTP libraries that will allow you to get at the raw response, or is constructing a request manually using sockets the only way?

I'm specifically trying to see what newline characters the server is sending.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱你不解释 2025-01-03 21:09:41

文档示例

import socket, ssl, pprint

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# require a certificate from the server
ssl_sock = ssl.wrap_socket(s,
                           # http://curl.haxx.se/ca/cacert.pem
                           ca_certs="cacert.pem",
                           cert_reqs=ssl.CERT_REQUIRED)

ssl_sock.connect(('www.verisign.com', 443))

print repr(ssl_sock.getpeername())
print ssl_sock.cipher()
print pprint.pformat(ssl_sock.getpeercert())

# Set a simple HTTP request -- use httplib in actual code.
ssl_sock.write("""GET / HTTP/1.0\r
Host: www.verisign.com\r\n\r\n""")

# Read a chunk of data.  Will not necessarily
# read all the data returned by the server.
data = ssl_sock.read()
print repr(data)[:79]

# note that closing the SSLSocket will also close the underlying socket
ssl_sock.close()

输出

(ip, 443)
('DHE-RSA-AES256-SHA', 'TLSv1/SSLv3', 256)
{'notAfter': 'May 25 23:59:59 2012 GMT',
 'subject': ((('1.3.6.1.4.1.311.60.2.1.3', u'US'),),
             (('1.3.6.1.4.1.311.60.2.1.2', u'Delaware'),),
             (('businessCategory', u'V1.0, Clause 5.(b)'),),
             (('serialNumber', u'2497886'),),
             (('countryName', u'US'),),
             (('postalCode', u'94043'),),
             (('stateOrProvinceName', u'California'),),
             (('localityName', u'Mountain View'),),
             (('streetAddress', u'487 East Middlefield Road'),),
             (('organizationName', u'VeriSign, Inc.'),),
             (('organizationalUnitName', u' Production Security Services'),),
             (('commonName', u'www.verisign.com'),))}
'HTTP/1.1 200 OK\r\nDate: Thu, 19 Jan 2012 01:47:31 GMT\r\nServer: Apache\r\nSe

M2Crypto 示例

Example from the docs:

import socket, ssl, pprint

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# require a certificate from the server
ssl_sock = ssl.wrap_socket(s,
                           # http://curl.haxx.se/ca/cacert.pem
                           ca_certs="cacert.pem",
                           cert_reqs=ssl.CERT_REQUIRED)

ssl_sock.connect(('www.verisign.com', 443))

print repr(ssl_sock.getpeername())
print ssl_sock.cipher()
print pprint.pformat(ssl_sock.getpeercert())

# Set a simple HTTP request -- use httplib in actual code.
ssl_sock.write("""GET / HTTP/1.0\r
Host: www.verisign.com\r\n\r\n""")

# Read a chunk of data.  Will not necessarily
# read all the data returned by the server.
data = ssl_sock.read()
print repr(data)[:79]

# note that closing the SSLSocket will also close the underlying socket
ssl_sock.close()

Output

(ip, 443)
('DHE-RSA-AES256-SHA', 'TLSv1/SSLv3', 256)
{'notAfter': 'May 25 23:59:59 2012 GMT',
 'subject': ((('1.3.6.1.4.1.311.60.2.1.3', u'US'),),
             (('1.3.6.1.4.1.311.60.2.1.2', u'Delaware'),),
             (('businessCategory', u'V1.0, Clause 5.(b)'),),
             (('serialNumber', u'2497886'),),
             (('countryName', u'US'),),
             (('postalCode', u'94043'),),
             (('stateOrProvinceName', u'California'),),
             (('localityName', u'Mountain View'),),
             (('streetAddress', u'487 East Middlefield Road'),),
             (('organizationName', u'VeriSign, Inc.'),),
             (('organizationalUnitName', u' Production Security Services'),),
             (('commonName', u'www.verisign.com'),))}
'HTTP/1.1 200 OK\r\nDate: Thu, 19 Jan 2012 01:47:31 GMT\r\nServer: Apache\r\nSe

Example with M2Crypto.

一口甜 2025-01-03 21:09:41

这取决于您要如何处理结果。 httplib.HTTPSConnectionset_debuglevel 方法,允许将响应数据打印到 stdout(尽管每行都有前缀)。出于调试目的,这正是我所需要的。不确定,这就是你所需要的。

It depends on what you are going to do with the result. httplib.HTTPSConnection has set_debuglevel method which allows printing the response data to stdout (though each line is prefixed). For debugging purposes that was exactly what I needed. Not sure, it is what you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文