Pregunta

I'm developing a dart application which will consume a REST service I'm building. I started writing out the dart code to perform an ajax request to my login endpoint. However, even when my dart ajax request should fail, it claims to succeed.

I don't have any services up and running (and even if I did it would be using the wrong domain / port right now), but this code gives a 200 OK HttpResponse every time:

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");
  }
}

It always hits the processLogin method, and never hits the processLoginError method. Does anyone have any idea why this would be? Should I be performing this ajax request in a different way? (If you couldn't guess, it will be signing into spring security).

I read somewhere that file system requests always succeed. Is Dart somehow making this a file system request rather than a web request?

¿Fue útil?

Solución

This is because the request actually completes successfully.

Your request to "login" will actually call http://127.0.0.1:6521/[Path_to_your_Dart_file]/login

The server started by Dart when running in Dartium (127.0.0.1:6521) seems to answer to every POST request with HTTP 200 and an empty response body.

If you change the method from POST to GET, it will fail as expected.

As for why the server does this - I don't really know. This would have to be answered by the Dart team.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top