Guest User

helps

a guest
Aug 16th, 2021
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Serialization;
  6. using Proyecto26;
  7. using UnityEditor;
  8. using UnityEngine.Networking;
  9. using System.Text;
  10. using TMPro;
  11. using SimpleJSON;
  12.  
  13. public class APIRequest
  14. {
  15.    // string basicRequestPage = "****";
  16.     string basicAPI_Key = "****";
  17.     // Start is called before the first frame update
  18.  
  19.     string outputs;
  20.  
  21.  
  22.     public string basicRequest(int requestTyp)
  23.     {
  24.  
  25.  
  26.         auth test1 = new auth();
  27.  
  28.         test1.key = basicAPI_Key;
  29.  
  30.  
  31.         switch (requestTyp)
  32.         {
  33.             case 0:
  34.                 test1.request = "deckList";
  35.                 break;
  36.             case 1:
  37.                 test1.request = "card";
  38.                 break;
  39.  
  40.         }
  41.         string output = JsonConvert.SerializeObject(test1);
  42.  
  43.         byte[] outputToServer = Encoding.ASCII.GetBytes(output); ;
  44.  
  45.  
  46.         //Debug.Log(output);
  47.  
  48.         RestClient.Request(new RequestHelper
  49.         {
  50.             Uri = basicRequestPage,
  51.             Method = "POST",
  52.             Timeout = 10,
  53.             //EnableDebug = true,
  54.             ParseResponseBody = false, //Don't encode and parse downloaded data as JSONe
  55.             BodyRaw = outputToServer
  56.         }).Then(response =>
  57.         {
  58.             // EditorUtility.DisplayDialog("Status", response.Text, "Ok");
  59.             var rest = response.Text;
  60.             //Debug.Log(rest);
  61.             outputs = rest.ToString();
  62.             //EditorUtility.DisplayDialog("Status", outputs, "Ok");
  63.             return outputs;
  64.  
  65.         }).Catch(err =>
  66.         {
  67.             var error = err as RequestException;
  68.             EditorUtility.DisplayDialog("Error Response", error.Response + "", "Ok");
  69.  
  70.  
  71.         }
  72.  
  73.  
  74.         );
  75.  
  76.  
  77.     }
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment