Last active
September 27, 2018 22:29
-
-
Save mvgolom/8cd4d4de3e5ba02e51bf28a0ba0dfbfb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //do tutorial | |
| dotnet new console | |
| dotnet restore | |
| dotnet run | |
| //para adicionar um pacote de manipulacao de json | |
| dotnet add package Newtonsoft.Json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.IO; | |
| using System.Net; | |
| using System.Text; | |
| using System.Collections.Generic; | |
| using Newtonsoft.Json; | |
| namespace Sample{ | |
| //Modelo do Json | |
| public class Word{ | |
| public string Name { get; set; } | |
| public List<string> Anagrams { get; set; } | |
| } | |
| class Test | |
| { | |
| public static void Main(string[] args){ | |
| WebRequest request = WebRequest.Create("http://localhost:3000/newgame"); | |
| WebResponse response = request.GetResponse(); | |
| //Console.WriteLine (((HttpWebResponse)response).StatusDescription); | |
| Stream dataStream = response.GetResponseStream(); | |
| StreamReader reader = new StreamReader(dataStream); | |
| // Read the content. | |
| string responseFromServer = reader.ReadToEnd(); | |
| Console.WriteLine("Response:\n"); | |
| //Converte a String do request em json | |
| Word w = Newtonsoft.Json.JsonConvert.DeserializeObject<Word>(responseFromServer); | |
| Console.WriteLine(w.Name+":"); | |
| foreach (string elemento in w.Anagrams){ | |
| Console.WriteLine(elemento); | |
| } | |
| reader.Close (); | |
| dataStream.Close (); | |
| response.Close (); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment