python 版本
from flask import jsonify, Flask
app = Flask(__name__)
# 增加配置,支持中文显示
app.config['JSON_AS_ASCII'] = False
tasks = {
"success": "true",
"resultMsg": "请求成功",
"result": "1000"
}
@app.route('/task', methods=['GET','POST'])
def get_task():
return jsonify(tasks)
if __name__ == '__main__':
app.run(
host = '0.0.0.0',
port = 6868,
debug = True
)
node版本
var data = {
"code": 0,
"message": "success"
}
var http = require('http');
http.createServer(function(request,response){
response.writeHead(200,{'Content-Type':'application/json'});
response.end(JSON.stringify(data));
}
).listen(8888);
console.log('Server running at http://127.0.0.1:8888/');
这两种方法都可以模拟一个外部服务