Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
省道';s的http服务器引发异常_Http_Https_Dart - Fatal编程技术网

省道';s的http服务器引发异常

省道';s的http服务器引发异常,http,https,dart,Http,Https,Dart,这个简单的dart程序启动并运行一段时间,但在一些交互之后,它会引发一个异常: import 'dart:io'; import 'package:http_server/http_server.dart'; main() async { //files var staticFiles = new VirtualDirectory("/path ...."); staticFiles.allowDirectoryListing = true; staticFiles.dir

这个简单的dart程序启动并运行一段时间,但在一些交互之后,它会引发一个异常:

import 'dart:io';
import 'package:http_server/http_server.dart';

main() async {


  //files
  var staticFiles = new VirtualDirectory("/path ....");
  staticFiles.allowDirectoryListing = true;
  staticFiles.directoryHandler = (dir, request) {
    var indexUri = new Uri.file(dir.path).resolve('index.html');
    staticFiles.serveFile(new File(indexUri.toFilePath()), request);
  };


  //http
  HttpServer
    .bind(InternetAddress.ANY_IP_V6, 80)
    .then((server) {
      server.forEach(staticFiles.serveRequest);
    }
  );

  //https
  SecurityContext context = new SecurityContext();
  var chain =   Platform.script.resolve('file.pem').toFilePath();
  var key =    Platform.script.resolve('file.pem').toFilePath();
  context.useCertificateChain(chain);
  context.usePrivateKey(key, password: 'pwd');
  HttpServer
    .bindSecure(InternetAddress.ANY_IP_V6, 443, context)
    .then((server) {
      server.forEach(staticFiles.serveRequest);
    }
  );
}
一段时间后它崩溃了。例外情况是:

Unhandled exception:
SocketException: OS Error: Broken pipe, errno = 32, address = ::, port = 443
#0      _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1108)
#1      _microtaskLoop (dart:async/schedule_microtask.dart:41)
#2      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#3      _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:99)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:152)
但它没有帮助…

http_服务器(以及Dart的http支持)不支持基于密码的身份验证

您可以在核心支持之上构建这样的东西,但仅此而已

如果您正在寻找静态文件解决方案,我会


启动起来会容易得多。

我的程序引发异常的原因是什么?
import 'dart:io';
import 'package:http_server/http_server.dart';

main() async {


  //files
  var staticFiles = new VirtualDirectory("file");
  staticFiles.allowDirectoryListing = true;
  staticFiles.directoryHandler = (dir, request) {
    try{
      var indexUri = new Uri.file(dir.path).resolve('index.html');
      staticFiles.serveFile(new File(indexUri.toFilePath()), request);
    } catch(a,b) {
      print(a);
      print(b);
    }
  };


  //http
  HttpServer
    .bind(InternetAddress.ANY_IP_V6, 80)
    .then((server) {
      try{
        server.forEach(staticFiles.serveRequest);
      } catch(a,b)
      {
        print(a);
        print(b);
      }
    }
  );

  //https
  SecurityContext context = new SecurityContext();
  var chain =   Platform.script.resolve('file.pem').toFilePath();
  var key =    Platform.script.resolve('file.pem').toFilePath();
  context.useCertificateChain(chain);
  context.usePrivateKey(key, password: 'pwd');
  HttpServer
    .bindSecure(InternetAddress.ANY_IP_V6, 443, context)
    .then((server) {
        try {
          server.forEach(staticFiles.serveRequest);
        } catch(a, b){
          print(a);
          print(b);
        }
      }
  );