Advertisement
Guest User

Untitled

a guest
May 31st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.89 KB | None | 0 0
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Net.Http;
  7. using Newtonsoft.Json;
  8.  
  9. using System.Net.Http.Headers;
  10. using System.Runtime.Serialization;
  11. using System.IO;
  12. using System.Text;
  13. using System.Net;
  14.  
  15. namespace ConsoleProgram
  16. {
  17.  
  18.  
  19.  
  20.     public class Sappinighi
  21.     {
  22.         public M2mAE m2mAE { get; set; }
  23.     }
  24.  
  25.     public class M2mAE
  26.     {
  27.         public string parentID { get; set; }
  28.         public int resourceType { get; set; }
  29.         public string creationTime { get; set; }
  30.         public string resourceID { get; set; }
  31.         public string resourceName { get; set; }
  32.         public string lastModifiedTime { get; set; }
  33.         public string expirationTime { get; set; }
  34.         public string[] accessControlPolicyIDs { get; set; }
  35.         public string AEID { get; set; }
  36.         public bool requestReachability { get; set; }
  37.     }
  38.  
  39.  
  40.     public class Class1
  41.     {
  42.         private const string URL = "http://163.162.63.18:7579/";
  43.         private const string urlParameters = "onem2m/blockchain";
  44.  
  45.         static void Main(string[] args)
  46.         {
  47.             HttpClient client = new HttpClient();
  48.             client.BaseAddress = new Uri(URL);
  49.            
  50.  
  51.             // Add an Accept header for JSON format.
  52.             //client.DefaultRequestHeaders.Accept.Add(
  53.             // new MediaTypeWithQualityHeaderValue("application/json"));
  54.  
  55.             String username = "blockchain";
  56.             String password = "block";
  57.             String encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
  58.            
  59.  
  60.  
  61.             client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", encoded);
  62.             client.DefaultRequestHeaders.Add("X-M2M-RI", "12345");
  63.             client.DefaultRequestHeaders.Add("X-M2M-Origin", "blockchain_cons");
  64.             client.DefaultRequestHeaders.Add("Accept", "application/json");
  65.             client.DefaultRequestHeaders.Add("nmtype", "long");
  66.  
  67.  
  68.             //Console.WriteLine(client.GetAsync(urlParameters).Result);
  69.             // List data response.
  70.  
  71.             HttpResponseMessage response = client.GetAsync(urlParameters).Result;  // Blocking call!
  72.             if (response.IsSuccessStatusCode)
  73.             {
  74.                 // Parse the response body. Blocking!
  75.                
  76.  
  77.                 Console.WriteLine(response);
  78.  
  79.                 Console.ReadLine();
  80.                 //foreach (var d in sapp)
  81.                 //{
  82.                 //    Console.WriteLine("{0}", d.m2mAE);
  83.                 //}
  84.             }
  85.             else
  86.             {
  87.                 Console.WriteLine("ciao");
  88.                 Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
  89.                 Console.ReadLine();
  90.             }
  91.  
  92.  
  93.  
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement