【问题标题】:Dart request succeeding ... somehow?飞镖请求成功......不知何故?
【发布时间】:2013-08-09 19:52:33
【问题描述】:

我正在开发一个 dart 应用程序,它将使用我正在构建的 REST 服务。我开始编写 dart 代码来向我的登录端点执行 ajax 请求。但是,即使我的 dart ajax 请求失败,它也声称成功。

我没有启动并运行任何服务(即使我这样做了,现在也会使用错误的域/端口),但是这段代码每次都会给出 200 OK HttpResponse:

class PlayerController {

  const PlayerController();

  static const String LOGIN_URL = "login";

  void login(String username, String password) {
    Map<String, String> headers = {"Content-Type": "application/x-www-form-urlencoded"};
    String body = "j_username=$username&j_password=$password&submit=Login";
    HttpRequest.request(LOGIN_URL, method: "POST", requestHeaders: headers, sendData: body)
      .then((request) => processLogin(request, username))
      .catchError((e) => processLoginError(e));
  }

  void processLogin(var whatIsThis, String username) {
    query("#loginButton").text = "Logout";
    //TODO get the player then set them
  }

  void processLoginError(var e) {
    print("total failure to login because of $e");
  }
}

它总是命中 processLogin 方法,从不命中 processLoginError 方法。有谁知道为什么会这样?我应该以不同的方式执行这个 ajax 请求吗? (如果你猜不出来,它将登录 Spring Security)。

我在某处读到文件系统请求总是成功的。 Dart 是否以某种方式将此作为文件系统请求而不是 Web 请求?

【问题讨论】:

  • 你可以使用类似 http::localhost:8080/login 作为 URL 吗?否则,引用文档Requests to file:// URIs will also never fail- the Future will always complete successfully, even when the file cannot be found.

标签: dart dart-webui dartium


【解决方案1】:

这是因为请求实际上成功完成了。

您的“登录”请求实际上会调用http://127.0.0.1:6521/[Path_to_your_Dart_file]/login

在 Dartium (127.0.0.1:6521) 中运行时由 Dart 启动的服务器似乎使用 HTTP 200 和空响应正文响应每个 POST 请求。

如果您将方法从 POST 更改为 GET,它将按预期失败。

至于服务器为什么这样做 - 我真的不知道。这必须由 Dart 团队来回答。

【讨论】:

  • 奇怪。我认为,在尝试测试您是否有实际工作时,误报永远不会有帮助。也许我会尝试搜索他们的问题,看看是否存在。
  • 没看到,所以发了new one
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-21
  • 2019-11-22
  • 2014-03-09
  • 2022-11-15
  • 1970-01-01
相关资源
最近更新 更多