Exemplo n.º 1
0
        public static string GetString(BloomServer server, string endPoint, string query = "",
                                       ContentType returnType = ContentType.Text, EndpointHandler handler = null, string endOfUrlForTest = null, int?timeoutInMilliseconds = null)
        {
            if (handler != null)
            {
                server.ApiHandler.RegisterEndpointLegacy(endPoint, handler, true);
            }
            server.EnsureListening();
            var client = new WebClientWithTimeout
            {
                Timeout = timeoutInMilliseconds ?? 3000,
            };

            client.Headers[HttpRequestHeader.ContentType] = returnType == ContentType.Text ? "text/plain" : "application/json";

            if (endOfUrlForTest != null)
            {
                return(client.DownloadString(BloomServer.ServerUrlWithBloomPrefixEndingInSlash + "api/" + endOfUrlForTest));
            }
            else
            {
                if (!string.IsNullOrEmpty(query))
                {
                    query = "?" + query;
                }
                return(client.DownloadString(BloomServer.ServerUrlWithBloomPrefixEndingInSlash + "api/" + endPoint + query));
            }
        }
Exemplo n.º 2
0
        public static string PostString(BloomServer server, string endPoint, string data, ContentType returnType,
                                        EndpointHandler handler = null, int?timeoutInMilliseconds = null)
        {
            if (handler != null)
            {
                server.ApiHandler.RegisterEndpointLegacy(endPoint, handler, true);
            }
            server.EnsureListening();
            var client = new WebClientWithTimeout
            {
                Timeout = timeoutInMilliseconds ?? 3000
            };

            client.Headers[HttpRequestHeader.ContentType] = returnType == ContentType.Text ? "text/plain" : "application/json";

            return(client.UploadString(BloomServer.ServerUrlWithBloomPrefixEndingInSlash + "api/" + endPoint, "POST", data));
        }