Last active
October 4, 2018 16:52
-
-
Save troy-lamerton/9f395f5d3ae511466a24e27fbb75d10f 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
// add this import | |
using System.Net.Http; | |
public class Requests { | |
// Doing a GET request | |
void GetRequest() { | |
// create an http client | |
var client = new HttpClient(); | |
// send request and use .Result to wait for the response | |
var response = client.GetAsync("http://names.drycodes.com/1").Result; | |
Debug.Log("Was the GET request successful ?"); | |
Debug.Log(response.IsSuccessStatusCode); | |
// read the response stream | |
// and use .Result to wait for the whole string to be read | |
string responseData = response.Content.ReadAsStringAsync().Result; | |
// this line needs fixing | |
string justTheName = responseData.Substring(2, 10); | |
Debug.Log(justTheName); | |
Debug.Log("Whole thing: " + responseData); | |
} | |
// Doing a POST request | |
void GetRequest() { | |
// Coming soon | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment