Guest User

Untitled

a guest
Jan 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. internal static JObject GetToBackOffice(string action)
  2. {
  3. var url = backOfficeUrl;
  4. url = url + action;
  5.  
  6. HttpClient httpClient = new HttpClient();
  7.  
  8. var response =
  9. httpClient.GetAsync(url
  10. ).Result;
  11. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  12. {
  13. var idProcess = Newtonsoft.Json.Linq.JObject.Parse(response.Content.ReadAsStringAsync().Result);
  14.  
  15. return idProcess;
  16. }
  17. else
  18. return null;
  19.  
  20. internal static JObject GetToBackOffice(string action)
  21. {
  22. var url = backOfficeUrl;
  23. url = url + action;
  24.  
  25. HttpClient httpClient = new HttpClient();
  26.  
  27. JObject idProcess = new JObject();
  28.  
  29. httpClient.GetString(new Uri(url),
  30. (response) =>
  31. {
  32. // Raised when the download completes
  33. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  34. {
  35. idProcess = Newtonsoft.Json.Linq.JObject.Parse(response.Data);
  36. }
  37. else
  38. {
  39. idProcess = null;
  40. }
  41. });
  42. // Here I would like to wait for the response, so that idProcess is filled with the received data before returning
  43. return idProcess;
  44. }
  45.  
  46. IEnumerator WaitForResponce(ResponceType response)
  47. {
  48. while(response.Data == null)
  49. yield return new WaitForSeconds (0.02f);
  50. //do what you want here
  51.  
  52. }
  53.  
  54. httpClient.GetString(new Uri(url),
  55. (response) =>
  56. {
  57. // Raised when the download completes
  58. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  59. {
  60. //idProcess = Newtonsoft.Json.Linq.JObject.Parse(response.Data);
  61. StartCoroutine(WaitForResponce(responce));
  62. }
  63. else
  64. {
  65. idProcess = null;
  66. }
  67. });
Add Comment
Please, Sign In to add comment