Skip to content

Instantly share code, notes, and snippets.

@troy-lamerton
Last active October 4, 2018 16:52
Show Gist options
  • Save troy-lamerton/9f395f5d3ae511466a24e27fbb75d10f to your computer and use it in GitHub Desktop.
Save troy-lamerton/9f395f5d3ae511466a24e27fbb75d10f to your computer and use it in GitHub Desktop.
// 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