2
ユニティでPOSTリクエストを送信しようとしていますが、それを行う機能がスキップされるため、私はそれを行うことができません。 ログを追加して何が起こったのかを知り、「(post game after):postjsonの後に)機能を過ぎてしまったというテキストがログに表示されても「(post json)」というメッセージは表示されません。ユニティでPOSTリクエストを送信する
private static void SendGamePlayed() {
int incrementedGamePlayed = GetGamePlayed() + 1;
EventObject anEvent = CreateEvent(EVENT_GAME_PLAYED, incrementedGamePlayed, null, null);
AbcEvent aAbcEvent = new AbcEvent (bundleID, appToken, anEvent);
string json = JsonUtility.ToJson (aAbcEvent);
// test
Debug.Log("(send game played): " + json);
PostJSON (json, EVENT_ROUTE);
Debug.Log ("(send game played): after postjson");
SetGamePlayed (incrementedGamePlayed);
}
private static IEnumerator PostJSON(string jsonString, string route) {
// test
Debug.Log("(post json) called");
string url = SERVER_URL + route;
var request = new UnityWebRequest(url, "POST");
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonString);
request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw);
request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
Debug.Log ("(post json) before sending");
yield return request.Send();
Debug.Log ("(post json) after sending");
if (request.error != null) {
Debug.Log("request error: " + request.error);
} else {
Debug.Log("request success: " + request.downloadHandler.text);
}
}
ありがとうございました!
ええと、そういうことが起こっています。 – Programmer
驚くべき、私は今すぐ試してみるつもりです。ありがとう! – Steve
私はこれを "非同期"と呼んでいませんが、あなたのポイントは正しいです。 –