Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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