用python (2.*) 写一个简单的模拟桩并且打印出请求头和消息体,便于调试接口,看看请求头和body是否符合要求vi mockServer.py
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
print("Headers:")
for header, value in self.headers.items():
print("{}: {}".format(header, value))
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write("{'code':200,'msg':'success'}".encode('utf-8'))
def do_POST(self):
print("Headers:")
for header, value in self.headers.items():
print("{}: {}".format(header, value))
content_length = int(self.headers['Content-Length'])
post_data = self.rfile.read(content_length)
print("body:{}".format(post_data))
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write("{'code':200,'msg':'success'}".encode('utf-8'))
def run(server_class=HTTPServer, handler_class=SimpleHTTPRequestHandler):
server_address = ('', 8000)
httpd = server_class(server_address, handler_class)
print('Starting httpd...')
httpd.serve_forever()
if __name__ == '__main__':
run()
启动python mockServer.py
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。