arcticfox1919 / arowana

A lightweight HTTP server framework for Dart.
MIT License
21 stars 3 forks source link

怎么运行在手机上 电脑访问接口 能返回数据啊 #5

Open CoderWeiLee opened 11 months ago

CoderWeiLee commented 11 months ago

我想电脑访问手机启动服务的接口 获得数据

CoderWeiLee commented 11 months ago

监听运行在iphone上已经通过端口转发解决了,目前Get请求可以监听并且响应 但是Post请求一直报错 route not found

class TestChannel extends DefaultChannel {
   handleRequest(Request request) async {
     print("解析post请求中的参数...");
    // 解析POST请求体中的参数
    var body = await utf8.decodeStream(request.read());
    var decodedBody = jsonDecode(body);
    var name = decodedBody['name'];
    var age = decodedBody['age'];
    return Response.ok("name:$name, age:$age");
  }

  @override
  Future prepare() {
    print('current isolate [${Isolate.current.debugName}]');
    return super.prepare();
  }

  @override
  void entryPoint() {
    post('/hello', (r) => handleRequest(r));

    // // 分组路由
    // var r = group('/info');
    // get('/hello', (r) {
    //   return Response.ok('hello,arowana!');
    // });

  }
arcticfox1919 commented 11 months ago

@CoderWeiLee

  1. 在Flutter中不能使用热重载,重启编译运行APP
  2. 不要使用端口转发。保持手机与电脑在同一无线局域网,在pc上直接使用手机的局域网IP访问即可
CoderWeiLee commented 11 months ago

好的 我回头试一下 谢谢哈