Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何快速创建接口测试数据 #169

Open
itgoyo opened this issue Jul 15, 2019 · 1 comment
Open

如何快速创建接口测试数据 #169

itgoyo opened this issue Jul 15, 2019 · 1 comment

Comments

@itgoyo
Copy link
Owner

itgoyo commented Jul 15, 2019

方法一 Apache+php

先安装 Apache 服务器,然后编写 php 代码即可,例如:

<?php
echo '
{
	"resultCode": 0,
	"resultData": {
		"isFirstLogin": 1,
		"userType": "2",
		"userName": "itgoyo",
		"token": "5ae00462662f83bf1442d6e8a0c6c0a5"
	},
	"resultMessage": "登录成功!",
	"resutlState": "SUCCESS"
}
';
?>

方法二 nodejs

安装 nodejs,然后写 js 代码,本地服务器测试,个人建议把 json 数据先压缩去除不必要的字符,例如:

var http = require('http')
http.createServer(function (request, response) {

    response.writeHead(200, {
        'Content-Type': 'application/json'
    })
    response.end('{"resultCode":0,"resultData":{"isFirstLogin":1,"userType":"2","userName":"wujiafu","token":"5ae00462662f83bf1442d6e8a0c6c0a5"},"resultMessage":"登录成功!","resutlState":"SUCCESS"}');

}).listen(8888);

console.log('Server running');

这样子可以快速自定义返回数据类型,真是太方便了,不用再写 java 代码呢

@itgoyo
Copy link
Owner Author

itgoyo commented Jun 4, 2020

由于nodejs存在跨域的问题,所以代码优化了一下:

var http = require('http')
http.createServer(function (request, response) {

    response.writeHead(200, {
        'Content-Type': 'application/json',
        'Access-Control-Allow-Origin': '*'
    })
    response.end('{"resultCode":0,"resultData":{"isFirstLogin":1,"userType":"2","userName":"wujiafu","token":"5ae00462662f83bf1442d6e8a0c6c0a5"},"resultMessage":"登录成功!","resutlState":"SUCCESS"}');

}).listen(8888);

console.log('Server running');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant