zoukankan      html  css  js  c++  java
  • HttpClient

    HttpSelfHostServer server = null;
                try
                {
                    // Set up server configuration
                    HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(_baseAddress);
                    config.MapHttpAttributeRoutes();
    
                    config.Routes.MapHttpRoute(
                        name: "DefaultApi",
                        routeTemplate: "api/{controller}/{id}",
                        defaults: new { id = RouteParameter.Optional }
                    );
    
                    // Create server
                    server = new HttpSelfHostServer(config);
    
                    // Start listening
                    server.OpenAsync().Wait();
                    Console.WriteLine("Listening on " + _baseAddress);
    
                    // Call the web API and display the result
                    HttpClient client = new HttpClient();
                    client.GetStringAsync(_address).ContinueWith(
                        getTask =>
                        {
                            if (getTask.IsCanceled)
                            {
                                Console.WriteLine("Request was canceled");
                            }
                            else if (getTask.IsFaulted)
                            {
                                Console.WriteLine("Request failed: {0}", getTask.Exception);
                            }
                            else
                            {
                                Console.WriteLine("Client received: {0}", getTask.Result);
                            }
                        });
                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Could not start server: {0}", e.GetBaseException().Message);
                    Console.WriteLine("Hit ENTER to exit...");
                    Console.ReadLine();
                }
                finally
                {
                    if (server != null)
                    {
                        // Stop listening
                        server.CloseAsync().Wait();
                    }
                }
  • 相关阅读:
    Android开发入门经典【申明:来源于网络】
    Java 的局部变量和成员变量
    js数组基础知识链接
    mongodb学习笔记2
    docker离线安装
    mongodb学习笔记
    jupyter notebook安装
    执行docker ps命令挂住问题分析
    keras安装简介(windows)
    mybatis查询日期和log4j2配置
  • 原文地址:https://www.cnblogs.com/HalloWorld/p/6624408.html
Copyright © 2011-2022 走看看