Beispiel #1
0
 internal static bool checkResult(HttpResponseAndData resAndData, string errorMessage, bool isData)
 {
     if (resAndData.status == HttpStatusCode.OK)
     {
         return(true);
     }
     try
     {
         var dr = JsonConvert.DeserializeObject <DataResponse>(DEFAULT_ENCODING.GetString(resAndData.result));
         if (dr.error.ContainsKey("message"))
         {
             var exceptionMessage = errorMessage + " - reason: " + dr.error["message"];
             if (isData)
             {
                 throw new DataApiException(exceptionMessage);
             }
             else
             {
                 throw new AlgorithmException(exceptionMessage);
             }
         }
     }
     catch (Exception e)
     {
         if (e is AlgorithmiaException)
         {
             throw e;
         }
     }
     throw new AlgorithmiaException(errorMessage);
 }
Beispiel #2
0
        internal HttpResponseAndData postJsonHelper(string url, object inputObject, Dictionary <string, string> queryParameters)
        {
            var isByteArray = inputObject != null && inputObject.GetType().Name.ToLower() == "byte[]";

            HttpResponseAndData result = null;

            if (isByteArray)
            {
                result = synchronousHttpCall(HttpMethod.Post, url, queryParameters, new ByteArrayContent((byte[])inputObject), "application/octet-stream");
            }
            else
            {
                using (var stream = new MemoryStream())
                {
                    StreamWriter writer = new StreamWriter(stream);
                    writer.Write(JsonConvert.SerializeObject(inputObject));
                    writer.Flush();
                    stream.Flush();
                    stream.Position = 0;
                    result          = synchronousHttpCall(HttpMethod.Post, url, queryParameters, new StreamContent(stream), "application/json");
                }
            }
            return(result);
        }