本文整理汇总了Python中http.server.BaseHTTPRequestHandler.send_response方法的典型用法代码示例。如果您正苦于以下问题:Python BaseHTTPRequestHandler.send_response方法的具体用法?Python BaseHTTPRequestHandler.send_response怎么用?Python BaseHTTPRequestHandler.send_response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http.server.BaseHTTPRequestHandler
的用法示例。
在下文中一共展示了BaseHTTPRequestHandler.send_response方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_header
# 需要导入模块: from http.server import BaseHTTPRequestHandler [as 别名]
# 或者: from http.server.BaseHTTPRequestHandler import send_response [as 别名]
def send_header(BaseHTTPRequestHandler):
BaseHTTPRequestHandler.send_response(200)
BaseHTTPRequestHandler.send_header('Access-Control-Allow-Origin', '*')
BaseHTTPRequestHandler.send_header('Content-type:', 'text/html')
BaseHTTPRequestHandler.end_headers()
BaseHTTPRequestHandler.wfile.write(bytes('\n', 'utf-8'))
BaseHTTPRequestHandler.wfile.write(bytes('<html>\n', 'utf-8'))
示例2: send_response
# 需要导入模块: from http.server import BaseHTTPRequestHandler [as 别名]
# 或者: from http.server.BaseHTTPRequestHandler import send_response [as 别名]
def send_response(self, code: Union[int, HTTPStatus], message=None):
"""Fill in HTTP status message if not set."""
if message is None:
if isinstance(code, HTTPStatus):
message = code.phrase
code = code.value
BaseHTTPRequestHandler.send_response(self, code=code, message=message)
示例3: send_response
# 需要导入模块: from http.server import BaseHTTPRequestHandler [as 别名]
# 或者: from http.server.BaseHTTPRequestHandler import send_response [as 别名]
def send_response(self, mesg, code=200, headers=None):
'Wraps sending a response down'
if not headers:
headers = {}
if 'Content-Type' not in headers:
headers['Content-Type'] = 'text/html'
BaseHTTPRequestHandler.send_response(self, code)
self.send_header('Content-Length', len(mesg))
if headers:
for k, v in headers.items():
self.send_header(k, v)
self.end_headers()
self.wfile.write(mesg)
示例4: send_header
# 需要导入模块: from http.server import BaseHTTPRequestHandler [as 别名]
# 或者: from http.server.BaseHTTPRequestHandler import send_response [as 别名]
def send_header(BaseHTTPRequestHandler, format='HTML'):
if format.upper() == 'HTML':
BaseHTTPRequestHandler.send_response(200)
BaseHTTPRequestHandler.send_header('Access-Control-Allow-Origin', '*')
BaseHTTPRequestHandler.send_header('Content-type:', 'text/html')
BaseHTTPRequestHandler.end_headers()
BaseHTTPRequestHandler.wfile.write(bytes('\n', 'utf-8'))
BaseHTTPRequestHandler.wfile.write(bytes('<html>\n', 'utf-8'))
elif format.upper() == 'JSON':
BaseHTTPRequestHandler.send_response(200)
BaseHTTPRequestHandler.send_header('Access-Control-Allow-Origin', '*')
BaseHTTPRequestHandler.send_header('Content-type:', 'application/json')
BaseHTTPRequestHandler.end_headers()
示例5: send_response
# 需要导入模块: from http.server import BaseHTTPRequestHandler [as 别名]
# 或者: from http.server.BaseHTTPRequestHandler import send_response [as 别名]
def send_response(self, code):
"""
See Python's BaseHTTPRequestHandler.send_response().
"""
BaseHTTPRequestHandler.send_response(self, code)
self.send_header("Connection", "close")
示例6: send_response
# 需要导入模块: from http.server import BaseHTTPRequestHandler [as 别名]
# 或者: from http.server.BaseHTTPRequestHandler import send_response [as 别名]
def send_response(self, code, message=None):
BaseHTTPRequestHandler.send_response(self,
self.server.override_code or code, message)