【发布时间】:2017-06-04 03:49:18
【问题描述】:
我正在尝试向使用 Eve 作为框架的 Rest API 发出 POST 请求,但是每当我尝试 POST 我的 JSON 我收到 422 错误,说明无法处理的实体。我的 GET 请求运行良好。这是我的 Eve 应用程序架构:
schema = {
'_update': {
'type': 'datetime',
'minlength': 1,
'maxlength': 40,
'required': False,
'unique': True,
},
'Name': {
'type': 'string',
'minlength': 1,
'maxlength': 40,
'required': True,
'unique': False,
},
'FacebookId': {
'type': 'integer',
'minlength': 1,
'maxlength': 40,
'required': True,
'unique': True,
},
'HighScore': {
'type': 'integer',
'minlength': 1,
'maxlength': 40,
'required': True,
'unique': False,
},
}
这是我要发布的 JSON:
{"_updated":null,"Name":"John Doe","FacebookId":"12453523434324123","HighScore":15}
这是我尝试从客户端发出 POST 请求的方式:
IDictionary dict = Facebook.MiniJSON.Json.Deserialize(result.RawResult) as IDictionary;
string name = dict["name"].ToString();
string id = dict["id"].ToString();
Player player = new Player();
player.FacebookId = id;
player.Name = name;
player.HighScore = (int) GameManager.Instance.Points;
// Using Newtonsoft.Json to serialize
var json = JsonConvert.SerializeObject(player);
var headers = new Dictionary<string, string> {{"Content-Type", "application/json"}};
string url = "http://server.com/Players";
var encoding = new UTF8Encoding();
// Using Unity3d WWW class
WWW www = new WWW(url, encoding.GetBytes(json), headers);
StartCoroutine(WaitForRequest(www));
【问题讨论】:
标签: c# python json mongodb unity3d