1
我試着做一個POST請求,這是使用夏娃爲骨架我的REST API,但是每當我試圖POST我JSON我得到一個422錯誤說無法處理的實體。我的GET請求工作得很好。這是我爲我的夏娃應用模式:422錯誤:Python的POST請求
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));