예제 #1
0
 //Call post method
 public static JObject postResource(string endpoint, string jsonString)
 {
     try
     {
         var jsonData = new StringContent(jsonString, Encoding.UTF8, "application/json");
         var client   = new HttpClient();
         client.BaseAddress = new Uri(WORLDBANK_ROOT);
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         HttpResponseMessage response = client.PostAsync(endpoint, jsonData).Result;
         if (response.IsSuccessStatusCode)
         {
             var    data = response.Content.ReadAsStringAsync().Result;
             Object rs   = JsonConvert.DeserializeObject(data);
             return(JObject.Parse(WorldBankWebservices.getJsonResultString(WorldBankWebservices.SUCCESS, rs, "")));
         }
         else
         {
             return(JObject.Parse(WorldBankWebservices.getJsonResultString(WorldBankWebservices.ERROR, "", response.ToString())));
         }
     }
     catch (Exception e)
     {
         return(JObject.Parse(WorldBankWebservices.getJsonResultString(WorldBankWebservices.ERROR, "", e.Message)));
     }
 }
예제 #2
0
 //Call get method
 public static JObject getResource(string endpoint)
 {
     try
     {
         var client = new HttpClient();
         client.BaseAddress = new Uri(WORLDBANK_ROOT);
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         HttpResponseMessage response = client.GetAsync(endpoint).Result;
         if (response.IsSuccessStatusCode)
         {
             var data = response.Content.ReadAsStringAsync().Result;
             return(JObject.Parse(WorldBankWebservices.getJsonResultString(WorldBankWebservices.SUCCESS, data, "")));
         }
         else
         {
             return(JObject.Parse(WorldBankWebservices.getJsonResultString(WorldBankWebservices.ERROR, "", response.ToString())));
         }
     }
     catch (Exception e)
     {
         return(JObject.Parse(WorldBankWebservices.getJsonResultString(WorldBankWebservices.ERROR, "", e.Message)));
     }
 }