Пример #1
0
        //**********************Add new end point**********************
        static async Task AddNewEndpoint(string requestUri, string apiKey)
        {
            using (HttpClient client = new HttpClient())
            {
                WebServiceEndpoint request = new WebServiceEndpoint
                {
                    Description   = "New end point",
                    ThrottleLevel = "Low" //, High is available only for paid tier
                                          //MaxConcurrentCalls = "500" //not available for free trial
                };

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

                var requestMessage = new HttpRequestMessage(new HttpMethod("PUT"), requestUri)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(request), Encoding.Default, "application/json")
                };

                Console.WriteLine("Starting create endpoint");

                var response = await client.SendAsync(requestMessage);

                string responseContent = await response.Content.ReadAsStringAsync();

                Console.WriteLine(responseContent);

                if (response.IsSuccessStatusCode)
                {
                    Console.WriteLine("Endpoint created.");
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("Response status code {0}", response.StatusCode);
                    Console.WriteLine("Endpoint creation failed: {0}", response.ToString());
                    Console.ReadLine();
                }
            }
        }
Пример #2
0
        //**********************Add new end point**********************
        static async Task AddNewEndpoint(string requestUri, string apiKey)
        {
            using (HttpClient client = new HttpClient())
            {
                WebServiceEndpoint request = new WebServiceEndpoint
                {
                    Description = "New end point",
                    ThrottleLevel = "Low"//, High is available only for paid tier
                    //MaxConcurrentCalls = "500" //not available for free trial
                };

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

                var requestMessage = new HttpRequestMessage(new HttpMethod("PUT"), requestUri)
                {
                    Content = new StringContent(JsonConvert.SerializeObject(request), Encoding.Default, "application/json")
                };

                Console.WriteLine("Starting create endpoint");

                var response = await client.SendAsync(requestMessage);
                string responseContent = await response.Content.ReadAsStringAsync();

                Console.WriteLine(responseContent);

                if (response.IsSuccessStatusCode)
                {
                    Console.WriteLine("Endpoint created.");
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("Response status code {0}", response.StatusCode);
                    Console.WriteLine("Endpoint creation failed: {0}", response.ToString());
                    Console.ReadLine();
                }
            }
        }