I'm trying to send and $http.get()
request and authenticate it in the server side (WebApi)
$http.get(config.remoteServiceUrl + "api/account", {
headers:
{
'Authorization': 'Basic ' + encoded,
'Content-Type': "application/json"
},
params:
{
'email': credentials.Email
}
}).then(
//Success
function (data, status) {
setCredentials(credentials.Email, credentials.Password);
service.user.email = credentials.Email;
loggedin = true;
result.data = data;
result.status = status;
deferred.resolve(result);
},
//Error
function (data, status) {
result.data = data;
result.status = status;
deferred.reject(result);
}
);
for every unauthorized request the server should return a 401 status
HttpResponseMessage reply = request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Invalid Username or Password");
return Task.FromResult(reply);
but when i check the response in the client side the status is always empty instead of the 401 status.
below is the request being sent
Request URL:http://127.0.0.1:81/api/account?email=login@yahoo.com
Request Headersview source
Accept:application/json, text/plain, */*
Authorization:Basic bG9naW5AeWFob28uY29tOjExMTE=
Origin:http://localhost
Referer:http://localhost/EMR.WebUI/index.html
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
Query String Parametersview sourceview URL encoded
email:login@yahoo.com
when i check the request status after the call in the chrome debugger network tab is says
GET (Cancelled)
Anyone knows why this is happening?
It works correctly when a proper authorization is passed
Request URL:http://127.0.0.1:81/api/account?email=login@yahoo.com
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fil,fil-PH;q=0.8,tl;q=0.6,en-US;q=0.4,en;q=0.2
Authorization:Basic bG9naW5AeWFob28uY29tOjE=
Connection:keep-alive
Host:127.0.0.1:81
Origin:http://localhost
Referer:http://localhost/EMR.WebUI/index.html
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
Query String Parametersview sourceview URL encoded
email:login@yahoo.com
Response Headersview source
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Content-Length:110
Content-Type:application/json; charset=utf-8
Date:Mon, 13 Jan 2014 11:00:35 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/8.0
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET