我嘗試過使用以下的程式碼
from http.server import BaseHTTPRequestHandler, HTTPServer
from numbers import Number
times = None
class RequestHandler_httpd(BaseHTTPRequestHandler):
def do_GET(self):
global times
times = (times if isinstance(times, Number) else 0) + 1
messagetosend = bytes(times,"utf")
self.send_response(200)
self.send_header('Content-Type', 'text/plain')
self.send_header('Content-Length', len(messagetosend))
self.end_headers()
self.wfile.write(messagetosend)
print(self.requestline)
return
server_address_httpd = ('IP',8080)
httpd = HTTPServer(server_address_httpd, RequestHandler_httpd)
print('starting server')
httpd.serve_forever()
times = 0
但是當我在網址列輸入'IP':8080
時
得不到預期中的效果
請問可以幫忙修改程式碼嗎?
你的IP應該要是0.0.0.0
然後瀏覽器應該是打127.0.0.1