public async Task <JsonValue> RequestPost(string uriPart, string content) { if (uriPart.Contains("?")) { uriPart += $"&_token={token}"; } else { uriPart += $"?_token={token}"; } try { Console.WriteLine($"posting to {uriPart} with {content}"); //var httpRequest = new HttpRequestMessage(HttpMethod.Post, $"{baseAdress}{uriPart}"); var stringContent = new StringContent(content, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"{baseAdress}{uriPart}", stringContent); return(Parse(await response.Content.ReadAsStringAsync())); } catch (Exception e) { error = new ConnectorError(e.Message); return(Parse("{\"ok\":0}")); } }
public ConnectorError GetLastError() { if (null != error) { var ret = error; error = null; return(ret); } return(new ConnectorError("no error")); }
public Connector(string token, string server = "http://screeps.com/") { //fallback for screepsmod-auth try { baseAdress = server; //client.BaseAddress = new Uri(server); } catch (Exception e) { error = new ConnectorError("invalid server address"); } this.token = token; }
public async Task <JsonValue> RequestGet(string request) { if (request.Contains("?")) { request += $"&_token={token}"; } else { request += $"?_token={token}"; } try { var jsonString = await client.GetStringAsync($"{baseAdress}{request}"); return(Parse(jsonString)); } catch (Exception e) { error = new ConnectorError(e.Message); return(Parse("{\"ok\":0}")); } }