试图使用AngularJS $http访问WCF服务时出错。以下是AngularJS代码:
$http({
method: 'POST',
url: 'http://localhost:59412/ToDoService.svc/SignIn',
params: JSON.stringify({ username: 'jay' }),
headers: {
"Content-Type": "application/json"
}
})
.then(function (res) {
console.log(res);
})下面是web服务代码(ToDoService.svc.cs):
public void SignIn(string username)
{
}ToDoService.svc代码是:
[ServiceContract]
public interface IToDoService
{
[OperationContract]
[WebInvoke(Method = "POST")]
void SignIn(string username);
}浏览器控制台中显示的错误是:
POST http://localhost:59412/ToDoService.svc/SignIn?0=%7B&1=%22&10=%22&11=:&12=%22&13=j&14=a&15=y&16=%22&17=%7D&2=u&3=s&4=e&5=r&6=n&7=a&8=m&9=e 500 (Internal Server Error)注意:如果我从服务调用中删除params,可以正常工作。
发布于 2016-03-16 11:44:00
将params替换为data选项
data: JSON.stringify({ username: 'jay' })https://stackoverflow.com/questions/36034459
复制相似问题