private async Task <string> PostProblem(Problem.ProblemEnvelope envelope) { // we need to construct a http call. using (var client = new HttpClient()) { configureClient(client); byte[] envBytes = SerialiseObject <Problem.ProblemEnvelope>(envelope); var content = new ByteArrayContent(envBytes); content.Headers.ContentType = new MediaTypeHeaderValue("application/protobuf"); var result = client.PostAsync(EndPoint, content).Result; if (result.StatusCode == System.Net.HttpStatusCode.OK) { string resultContent = await result.Content.ReadAsStringAsync(); return(resultContent); } else { string resultContent = await result.Content.ReadAsStringAsync(); Console.WriteLine("Error connecting to api; http error: " + result.ReasonPhrase + "\n" + resultContent); } } return(""); }
public string Post(iT solveRequest) { var p = new Problem.ProblemEnvelope(); p.Type = ModelType; p.subType = 0; // for a post; p.Content = SerialiseObject <iT>(solveRequest); string res = PostProblem(p).Result; if (res == "") { throw new Exception("unable to retrieve a request id from the api. Is the URL correct? Is the model being rate limited? Have you enabled the service for the key being used?"); } else { postResponse resJson = JsonConvert.DeserializeObject <postResponse>(res); System.Threading.Thread.Sleep(100); // Feel free to remove this return(resJson.requestId); } }