Skip to content

Instantly share code, notes, and snippets.

@chrisngobanh
Created April 17, 2017 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisngobanh/51c9c4f7b6c3932cb487e5ea769f8ca1 to your computer and use it in GitHub Desktop.
Save chrisngobanh/51c9c4f7b6c3932cb487e5ea769f8ca1 to your computer and use it in GitHub Desktop.
// References:
// API Calls: https://github.com/Pirates-Bounty/pirates-backend
// How to make HTTP requests in C# [StackOverflow]: http://stackoverflow.com/questions/4015324/http-request-with-post
// NOTE: This code is very rough because I don't actually know C#, so it won't work right off the bat
using System.Net.Http;
class PiratesAPIClient {
private static readonly HttpClient client = new HttpClient();
/*
/user/create
Request Data:
* 'username': String, 3-20 characters
* 'password': String
Response Data:
* 'token': String
* 'session_ttl': Number/Date in UNIX time
*/
void createUser() {
// Values that we will send to the server. AKA Request Data
// Replace foo and bar with values that the user inputted
var values = new Dictionary<string, string>
{
{ "username", "foo" },
{ "password", "bar" }
};
var content = new FormUrlEncodedContent(values);
// Make POST request
var response = await client.PostAsync("http://pirates.chrisbanh.com/user/create", content);
var responseString = await response.Content.ReadAsStringAsync();
// not sure what to do from here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment