1

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?

1
  • 1
    Can you use something like http::localhost:8080/login as the URL? Otherwise, quoting the docs Requests to file:// URIs will also never fail- the Future will always complete successfully, even when the file cannot be found.
    – DrColossos
    Aug 8, 2013 at 13:43

1 Answer 1

2

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.

2
  • Strange. False positives are never helpful when trying to test whether you've got something actually working, I think. Maybe I'll try searching their issues to see if this exists.
    – CorayThan
    Aug 8, 2013 at 15:26
  • 1
    I didn't see one, so I made a new one
    – CorayThan
    Aug 8, 2013 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.