Unity3Dゲームエンジンのfirebaseクラウド機能プロジェクトにPOST Httpリクエストを作成する際に問題があります。UnityWebRequest Firebaseのクラウド機能へのHTTP POST
私はコード400応答を取得しておくと、私は次のエラーを確認できfirebaseコンソールで:
Error: invalid json at parse
を私は本当にHTTPリクエストに関する多くの知識を持っており、かなりの時間後にはありません私が助けを求めたい解決策を見つけようとするのです。ここで
は、クライアントのコードです:
public void RateLevel(string guid, int rating)
{
RateLevelRequest rlr = new RateLevelRequest (guid, rating.ToString());
string body = rlr.ToJson();
UnityWebRequest www = UnityWebRequest.Post("myurl", body);
www.SetRequestHeader ("Content-Type", "application/json");
StartCoroutine (MakeRequest (www));
}
/* * * * * * * * * * * * * * * * * * *
* AUXILIAR CLASS FOR HTTP REQUESTS *
* * * * * * * * * * * * * * * * * * */
[System.Serializable]
public class RateLevelRequest
{
public string guid;
public string rating;
public RateLevelRequest(string _guid, string _rating)
{
guid = _guid;
rating = _rating;
}
public string ToJson()
{
string json = JsonUtility.ToJson (this);
Debug.Log ("RateLevelRequest Json: " + json);
return json;
}
}
私はこのような値を使用して、JSONがよく形成されることを保証することができます。
{"guid":"fake-guid","rating":"-1"}
そして、ここにfirebase-functionsの私の現在の展開された機能があります。
exports.rate_level = functions.https.onRequest((req, res) => {
if(req.method === 'POST')
{
console.log('guid: ' + req.body.guid);
console.log('rating: ' + req.body.rating);
console.log('invented var: ' + req.body.myinvention);
if(req.body.guid && req.body.rating &&
(req.body.rating == 1 || req.body.rating == -1))
{
res.status(200).send('You are doing a post request with the right fields and values');
}
else
{
res.status(403).send('Required Fields are not Defined!')
}
}
else
{
res.status(403).send('Wrong Request Method!');
}
});
誰もこれを試して成功しましたか?
ありがとうございます!