ResponseToString() private static method

private static ResponseToString ( WebResponse webResponse ) : string
webResponse System.Net.WebResponse
return string
Exemplo n.º 1
0
 private static void ProcessHttpResponse(CallRequestContainer reqContainer)
 {
     try
     {
         HttpWebResponse httpWebResponse = (HttpWebResponse)reqContainer.HttpRequest.GetResponse();
         if (httpWebResponse.StatusCode == HttpStatusCode.OK)
         {
             reqContainer.JsonResponse = PlayFabWebRequest.ResponseToString(httpWebResponse);
         }
         if (httpWebResponse.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(reqContainer.JsonResponse))
         {
             reqContainer.JsonResponse = (reqContainer.JsonResponse ?? "No response from server");
             PlayFabWebRequest.QueueRequestError(reqContainer);
         }
         else
         {
             reqContainer.HttpState = HttpRequestState.Received;
         }
     }
     catch (Exception innerException)
     {
         string text = "Unhandled exception in ProcessHttpResponse : " + reqContainer.FullUrl;
         reqContainer.JsonResponse = (reqContainer.JsonResponse ?? text);
         Exception ex = new Exception(text, innerException);
         PlayFabWebRequest.QueueRequestError(reqContainer);
     }
 }
Exemplo n.º 2
0
 private static void Post(CallRequestContainer reqContainer)
 {
     try
     {
         reqContainer.HttpRequest             = (HttpWebRequest)WebRequest.Create(reqContainer.FullUrl);
         reqContainer.HttpRequest.UserAgent   = "UnityEngine-Unity; Version: " + PlayFabWebRequest._unityVersion;
         reqContainer.HttpRequest.SendChunked = false;
         reqContainer.HttpRequest.Proxy       = null;
         foreach (KeyValuePair <string, string> keyValuePair in reqContainer.RequestHeaders)
         {
             reqContainer.HttpRequest.Headers.Add(keyValuePair.Key, keyValuePair.Value);
         }
         reqContainer.HttpRequest.ContentType = "application/json";
         reqContainer.HttpRequest.Method      = "POST";
         reqContainer.HttpRequest.KeepAlive   = PlayFabSettings.RequestKeepAlive;
         reqContainer.HttpRequest.Timeout     = PlayFabSettings.RequestTimeout;
         reqContainer.HttpRequest.AllowWriteStreamBuffering = false;
         reqContainer.HttpRequest.Proxy            = null;
         reqContainer.HttpRequest.ContentLength    = reqContainer.Payload.LongLength;
         reqContainer.HttpRequest.ReadWriteTimeout = PlayFabSettings.RequestTimeout;
         using (Stream requestStream = reqContainer.HttpRequest.GetRequestStream())
         {
             requestStream.Write(reqContainer.Payload, 0, reqContainer.Payload.Length);
         }
         reqContainer.HttpState = HttpRequestState.Sent;
     }
     catch (WebException ex)
     {
         reqContainer.JsonResponse = (PlayFabWebRequest.ResponseToString(ex.Response) ?? (ex.Status + ": WebException making http request to: " + reqContainer.FullUrl));
         WebException ex2 = new WebException(reqContainer.JsonResponse, ex);
         PlayFabWebRequest.QueueRequestError(reqContainer);
     }
     catch (Exception innerException)
     {
         reqContainer.JsonResponse = "Unhandled exception in Post : " + reqContainer.FullUrl;
         Exception ex3 = new Exception(reqContainer.JsonResponse, innerException);
         PlayFabWebRequest.QueueRequestError(reqContainer);
     }
 }