private IEnumerator Post(CallRequestContainer reqContainer)
{
#if PLAYFAB_REQUEST_TIMING
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
var startTime = DateTime.UtcNow;
#endif
using (var www = new UnityWebRequest(reqContainer.FullUrl)
{
uploadHandler = new UploadHandlerRaw(reqContainer.Payload),
downloadHandler = new DownloadHandlerBuffer(),
method = "POST"
})
{
foreach (var headerPair in reqContainer.RequestHeaders)
{
if (!string.IsNullOrEmpty(headerPair.Key) && !string.IsNullOrEmpty(headerPair.Value))
www.SetRequestHeader(headerPair.Key, headerPair.Value);
else
Debug.LogWarning("Null header: " + headerPair.Key + " = " + headerPair.Value);
}
#if UNITY_2017_2_OR_NEWER
yield return www.SendWebRequest();
#else
yield return www.Send();
#endif
#if PLAYFAB_REQUEST_TIMING
stopwatch.Stop();
var timing = new PlayFabHttp.RequestTiming {
StartTimeUtc = startTime,
ApiEndpoint = reqContainer.ApiEndpoint,
WorkerRequestMs = (int)stopwatch.ElapsedMilliseconds,
MainThreadRequestMs = (int)stopwatch.ElapsedMilliseconds
};
PlayFabHttp.SendRequestTiming(timing);
#endif
if (!string.IsNullOrEmpty(www.error))
{
OnError(www.error, reqContainer);
}
else
{
try
{
byte[] responseBytes = www.downloadHandler.data;
string responseText = System.Text.Encoding.UTF8.GetString(responseBytes, 0, responseBytes.Length);
OnResponse(responseText, reqContainer);
}
catch (Exception e)
{
OnError("Unhandled error in PlayFabUnityHttp: " + e, reqContainer);
}
}
www.Dispose();
}
}