Beispiel #1
0
        IQueryResult <T> Post <T>(IQueryRequest queryRequest)
        {
            var queryResult = new QueryResult <T>();

            try
            {
                var request = WebRequest.Create(queryRequest.GetBaseUri());
                request.Timeout     = _clientConfig.ViewRequestTimeout;
                request.Method      = "POST";
                request.ContentType = "application/x-www-form-urlencoded";

                var bytes = System.Text.Encoding.UTF8.GetBytes(queryRequest.GetQueryParameters());
                request.ContentLength = bytes.Length;

                using (var stream = request.GetRequestStream())
                {
                    stream.Write(bytes, 0, bytes.Length);
                }

                var response = request.GetResponse();
                using (var stream = response.GetResponseStream())
                {
                    queryResult         = DataMapper.Map <QueryResult <T> >(stream);
                    queryResult.Success = queryResult.Status == QueryStatus.Success;
                }
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    var stream = e.Response.GetResponseStream();
                    queryResult = DataMapper.Map <QueryResult <T> >(stream);
                }
                queryResult.Exception = e;
                Log.Error(e);
            }
            catch (Exception e)
            {
                ProcessError(e, queryResult);
                Log.Error(e);
            }
            return(queryResult);
        }