python启动服务器查看访问ip

开启服务器查看访问ip

  • python3环境

python3环境安装https://www.jianshu.com/p/3d351bdd4196

#!/usr/bin/python
# encoding: utf-8
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
class TestHTTPHandle(BaseHTTPRequestHandler):
    def do_POST(self):
        print("demo job")
        print(self.headers)
        content_len = int(self.headers.get('content-length',0))
        post_body = self.rfile.read(content_len)
        print("receive message from server: ")
        print("---------打印输出监听到的结果----------")
        print(post_body)
        print("-------------------")
        self.send_response(200)
        self.end_headers()
def start_server(port):
        http_server = HTTPServer(('0.0.0.0', int(port)), TestHTTPHandle)
        http_server.serve_forever()
if __name__ == '__main__':
        start_server(8080)

待确定机器访问

curl -H "Content-Type: application/json" -X POST -d '{"user_id": "123", "coin":100, "success":1, "msg":"OK!" }' http://xxxx:8080

你可能感兴趣的:(python启动服务器查看访问ip)