Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Net.Http;
- using Newtonsoft.Json;
- using System.Net.Http.Headers;
- using System.Runtime.Serialization;
- using System.IO;
- using System.Text;
- using System.Net;
- namespace ConsoleProgram
- {
- public class Sappinighi
- {
- public M2mAE m2mAE { get; set; }
- }
- public class M2mAE
- {
- public string parentID { get; set; }
- public int resourceType { get; set; }
- public string creationTime { get; set; }
- public string resourceID { get; set; }
- public string resourceName { get; set; }
- public string lastModifiedTime { get; set; }
- public string expirationTime { get; set; }
- public string[] accessControlPolicyIDs { get; set; }
- public string AEID { get; set; }
- public bool requestReachability { get; set; }
- }
- public class Class1
- {
- private const string URL = "http://163.162.63.18:7579/";
- private const string urlParameters = "onem2m/blockchain";
- static void Main(string[] args)
- {
- HttpClient client = new HttpClient();
- client.BaseAddress = new Uri(URL);
- // Add an Accept header for JSON format.
- //client.DefaultRequestHeaders.Accept.Add(
- // new MediaTypeWithQualityHeaderValue("application/json"));
- String username = "blockchain";
- String password = "block";
- String encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
- client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", encoded);
- client.DefaultRequestHeaders.Add("X-M2M-RI", "12345");
- client.DefaultRequestHeaders.Add("X-M2M-Origin", "blockchain_cons");
- client.DefaultRequestHeaders.Add("Accept", "application/json");
- client.DefaultRequestHeaders.Add("nmtype", "long");
- //Console.WriteLine(client.GetAsync(urlParameters).Result);
- // List data response.
- HttpResponseMessage response = client.GetAsync(urlParameters).Result; // Blocking call!
- if (response.IsSuccessStatusCode)
- {
- // Parse the response body. Blocking!
- Console.WriteLine(response);
- Console.ReadLine();
- //foreach (var d in sapp)
- //{
- // Console.WriteLine("{0}", d.m2mAE);
- //}
- }
- else
- {
- Console.WriteLine("ciao");
- Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
- Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement