1.6 KiB
1.6 KiB
当 app.js
启动后,API 的测试地址为:
http://localhost:3000/run
测试方法
使用 curl
测试
-
测试 C 代码:
curl -X POST http://localhost:3000/run \ -H "Content-Type: application/json" \ -d '{ "code": "#include <stdio.h>\nint main() { printf(\"Hello, World!\\n\"); return 0; }", "language": "c" }'
-
测试 Java 代码:
curl -X POST http://localhost:3000/run \ -H "Content-Type: application/json" \ -d '{ "code": "public class Main { public static void main(String[] args) { System.out.println(\"Hello, World!\"); } }", "language": "java" }'
使用 Postman 测试
- 打开 Postman。
- 创建一个新的请求,选择
POST
方法。 - 设置请求 URL 为
http://localhost:3000/run
。 - 在
Headers
中添加:Key: Content-Type Value: application/json
- 在
Body
中选择raw
,并输入测试数据,例如:{ "code": "#include <stdio.h>\nint main() { printf(\"Hello, World!\\n\"); return 0; }", "language": "c" }
- 点击发送,查看返回结果。
返回结果示例
-
成功输出:
{ "output": "Hello, World!\n" }
-
编译错误(例如 C 代码语法错误):
{ "error": "main.c: In function 'main':\nmain.c:2:12: error: expected ';' before 'return'\n" }
-
运行时错误(例如除零错误):
{ "error": "Floating point exception (core dumped)" }