我有一个servicestack
并将 Restfull 与Authenticate
.
当我使用Dart
此代码进行身份验证时:
var request = new html.HttpRequest();
request.open('POST', "http://x.x.x.x:9998/auth/basic", async:false);
request.setRequestHeader("accept", "application/json");
request.setRequestHeader("content-type", "application/json");
request.setRequestHeader("authorization", "Basic YWRtaW46cGFzc3dvcmQ=");
request.send(null);
print(request.response); //OK -> Print {"SessionId":"1","UserName":"admin","ResponseStatus":{}}
...这发生在我调用此服务之前:
request.open('GET', "http://x.x.x.x:9998/hello/everybody?format=json", async:false);
request.setRequestHeader("accept", "application/json");
request.setRequestHeader("content-type", "application/json");
request.setRequestHeader("authorization", "Basic YWRtaW46cGFzc3dvcmQ=");
request.send(null);
print(request.response);
...在 request.send(null); 处给我错误输出显示;
加载资源失败:服务器响应状态为 401 (Unauthorized) http://xxxx:9998/hello/everybody?format=json
... 在 print(request.response) 处给我良好的输出显示;
{“结果”:“大家好”}
我的 Dart 代码有问题吗?正常吗。