python https服务器post

python https服务器post,python,https,server,Python,Https,Server,我正试图找到一个http服务器,它可以响应来自客户端的POST请求。python代码返回的是http代码000,而不是200/100。请告诉我代码中是否有任何问题 CURL请求返回000而不是200/100 curl-s-o/dev/null-I-w“{http_code}”-X POST-k 000 代码: 导入BaseHTTPServer,SimpleHTTPServer 导入ssl 导入日志记录 类GetHandler(SimpleHTTPServer.SimpleHTTPRequestH

我正试图找到一个http服务器,它可以响应来自客户端的POST请求。python代码返回的是http代码000,而不是200/100。请告诉我代码中是否有任何问题

CURL请求返回000而不是200/100 curl-s-o/dev/null-I-w“{http_code}”-X POST-k 000

代码:
导入BaseHTTPServer,SimpleHTTPServer
导入ssl
导入日志记录
类GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_获得(自我):
logging.error(self.headers)
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def do_POST(自我):
self.wfile.write(“POST!”)
Handler=GetHandler
logging.basicConfig(级别=logging.DEBUG)
httpd=BaseHTTPServer.HTTPServer((“10.1.4.179”,443),处理程序)
httpd.socket=ssl.wrap_socket(httpd.socket,certfile='/tftpboot/server.pem',server_-side=True)
httpd.永远为你服务()

尝试在邮政编码部分发送回复代码:

from http.server import BaseHTTPRequestHandler,HTTPServer, SimpleHTTPRequestHandler
import ssl
import logging

class GetHandler(SimpleHTTPRequestHandler):

        def do_GET(self):
            logging.error(self.headers)
            SimpleHTTPRequestHandler.do_GET(self)

        def do_POST(self):
            self.send_response(200)
            self.send_header('Content-type', 'text/html')
            self.end_headers()
            self.data_string = self.rfile.read(int(self.headers['Content-Length']))

            data = b'<html><body><h1>POST!</h1></body></html>'
            self.wfile.write(bytes(data))
            return

Handler=GetHandler

logging.basicConfig(level=logging.DEBUG)
httpd=HTTPServer(("localhost", 8080), Handler)
#httpd.socket =ssl.wrap_socket(httpd.socket, certfile='/tftpboot/server.pem', server_side=True)
httpd.serve_forever()

唯一的问题是我通过HTTP发出了请求,因此注释掉了加载证书的行。

我尝试过发送响应(200),但没有帮助。没有xml也会得到相同的结果。为了清楚起见,我确实得到了xml回复“POST!”。但问题是,地位永远是零。你可以自己剪贴试试。如果有人能帮忙,请告诉我@ply26你有没有选择尝试你的答案?对你有用吗?@dd76请现在检查一下。我已经更新了代码,它对我来说工作得非常好。嗨,Piy26,非常感谢。第一件事与o/p无关。即使是初始代码也为我提供了所需的o/p。但是它返回的http状态是0,而不是200。这是我的问题。如果您可以尝试下面的curl,“curl-s-o/dev/null-I-w”%{http_code}“-X POST-k”。此外,我正在寻找服务器支持SSL连接,而不是纯粹的HTTP
from http.server import BaseHTTPRequestHandler,HTTPServer, SimpleHTTPRequestHandler
import ssl
import logging

class GetHandler(SimpleHTTPRequestHandler):

        def do_GET(self):
            logging.error(self.headers)
            SimpleHTTPRequestHandler.do_GET(self)

        def do_POST(self):
            self.send_response(200)
            self.send_header('Content-type', 'text/html')
            self.end_headers()
            self.data_string = self.rfile.read(int(self.headers['Content-Length']))

            data = b'<html><body><h1>POST!</h1></body></html>'
            self.wfile.write(bytes(data))
            return

Handler=GetHandler

logging.basicConfig(level=logging.DEBUG)
httpd=HTTPServer(("localhost", 8080), Handler)
#httpd.socket =ssl.wrap_socket(httpd.socket, certfile='/tftpboot/server.pem', server_side=True)
httpd.serve_forever()
<html><body><h1>POST!</h1></body></html>