Dart lang设置请求标头给出Breaking on exception:错误:InvalidStateError:DOM Exception 11

时间:2013-06-06 18:03:36

标签: dart

我正在尝试解决如何在HttpRequest

中在Dart中设置请求标头
 HttpRequest req = new HttpRequest();
  req.setRequestHeader("Content-type","application/json");
  req.open("Get", gotest);
  req.onLoadEnd.listen((event) => onSuccess(req));
  req.send(null);

结果:

Breaking on exception: Error: InvalidStateError: DOM Exception 11

编辑: gotest设置为

  var gotest = "http://127.0.0.1:9900/janus/parameter/sampleCount/201/1225/1313";

2 个答案:

答案 0 :(得分:2)

我建议使用基于Future的API。你不必乱用open(),send()等等。

试试这个:

HttpRequest.request('/foo',
    method: 'GET',
    requestHeaders: {'Content-type': 'application/json'})
  .then(onSuccess)
  .catchError(handleTheError);

答案 1 :(得分:1)

正如documentation for setRequestHeader所述:

  

在使用此方法之前,您必须先致电open()

将这些行重新排序为:

HttpRequest req = new HttpRequest();
req.open("Get", "www.google.com");
req.setRequestHeader("Content-type","application/json");
...