示例#1
0
        /// <inheritdoc />
        public async Task <Stream> GetAsStreamAsync(string relativeUrl, IEnumerable <KeyValuePair <string, string> > parameters, CancellationToken cancellationToken)
        {
            var u = new UriBuilder(ServerURL);

            u.Path += relativeUrl;
            u.Query = GetQuery(parameters);

            HttpResponseMessage response;

            if (UriValidator.UriLength(u) > MaxUriLength)
            {
                u.Query  = null;
                response = await HttpClient.PostAsync(u.Uri, new FormUrlEncodedContent(parameters), cancellationToken);
            }
            else
            {
                response = await HttpClient.GetAsync(u.Uri, cancellationToken);
            }

            if (!response.IsSuccessStatusCode)
            {
                throw new SolrConnectionException(await response.Content.ReadAsStringAsync(), null, u.Uri.ToString());
            }

            return(await response.Content.ReadAsStreamAsync());
        }
示例#2
0
        public void UriLength_Equivalent()
        {
            var property =
                from uri in Property.ForAll(GenX.uri)
                let ub = new UriBuilder(uri)
                         let expected = ub.Uri.ToString().Length
                                        let actual = UriValidator.UriLength(ub)
                                                     select AssertEqual(expected : expected, actual : actual);

            Property.Check(property);
        }