public ServiceResponseScalar <Stream> Get(string uri) { var serviceResponse = new ServiceResponseScalar <Stream>("Success"); try { var task = GetAsync(uri); Task.WaitAll(task); serviceResponse.Scalar = task.Result; } catch (Exception e) { LogException(e, $"Failed to retrieve GET stream from URI: {uri}"); serviceResponse.SetError("Failed to retrieve GET stream for request."); } return(serviceResponse); }
//I don't think this is well liked... public ServiceResponseScalar <Stream> Post(string uri, IEnumerable <KeyValuePair <string, string> > headers) { var serviceResponse = new ServiceResponseScalar <Stream>("Success"); try { var task = PostAsync(uri, headers); Task.WaitAll(task); serviceResponse.Scalar = task.Result; } catch (Exception e) { var headersAsString = string.Join(", ", headers.Select(kv => $"{kv.Key}={kv.Value}")); var detailedError = $"Failed to retrieve POST stream from URI: {uri} with headers: {headersAsString}"; LogException(e, detailedError); serviceResponse.SetError("Failed to retrieve POST stream for request."); } return(serviceResponse); }