getAuthorizationStatus: function() {
var deferred = $q.defer();
$http({
method: "POST",
url: url,
data: {
username: $scope.username,
password: $scope.password
},
contentType: 'application/json',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}).success(deferred.resolve)
.error(deferred.reject);
return deferred.promise;
},
我的服務器端代碼:
[HttpPost]
public int ValidateUser([FromBody]Credentials credentials)
{
try
{
string username = credentials.username;
string password = credentials.password;
//Do stuff
}
catch (Exception ex)
{
throw ex;
return -1;
}
return -1; // not valid user
}
我有是我能夠打API方法的問題,但裏面的數據始終爲空。我曾嘗試過幾種組合:
data: JSON.stringify({
"username" : "username",
"password":"mypassword"
}),
沒有骰子。
我在做什麼錯?
你爲什麼要使用一個帖子?看起來你想要一個get。 – jbrown
這是客戶真正的問題嗎?任何服務器端Web框架都應該可以訪問數據正文。你在這裏建立了什麼服務器。 –
@jbrown不,您不想使用獲取用戶名和密碼的請求! –