【发布时间】:2015-11-25 09:23:13
【问题描述】:
GET 方法完美,但 POST 方法不行。调试时 strReturnValue 变量始终为空。当我继续时,状态是:405 Method Not Allowed。我做错了什么?
在 C# 中,我必须将方法从 POST 更改为 OPTIONS。
我正在使用 Restangular(角度 js)。这是前端功能:
var message = {
Name: new_player.name,
Created: (new Date()).toJSON(),
Affilation: new_player.human,
auth: new_player.auth
}
return Restangular.one('').post('CreatePlayer', message).then(function(){
console.log("Object saved OK");
}, function() {
console.log("There was an error saving");
});
编辑
[System.ServiceModel.OperationContract]
[System.ServiceModel.Web.WebInvoke(UriTemplate = "CreatePlayer", Method = "OPTIONS", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string CreatePlayer(System.IO.Stream data);
public string CreatePlayer(System.IO.Stream data) {
//convert stream data to StreamReader
System.IO.StreamReader reader = new System.IO.StreamReader(data);
//read StreamReader data as string
string XML_string = reader.ReadToEnd();
string result = XML_string;
//return the XMLString data
return result;
}
【问题讨论】:
-
请显示收到帖子的操作?
标签: c# angularjs wcf restangular