Beispiel #1
0
        public async Task HttpInvokeAsync()
        {
            var postResult = await HttpClientUtils.HttpInvokeAsync(
                "http://httpbin.org", HttpMethod.Post, "/post", new { post = 123 });

            var postResultObj = JsonConvert.DeserializeObject <dynamic>(postResult);

            Assert.Equal("{\"post\":123}", (string)postResultObj.data);
            Assert.Equal("application/json; charset=utf-8", (string)postResultObj.headers["Content-Type"]);
            Assert.Equal("http://httpbin.org/post", (string)postResultObj.url);
        }
        /// <summary>
        /// 提交内容到远程服务器, 并返回回应的内容
        /// </summary>
        protected Task <string> HttpInvokeAsync(HttpMethod method, string endpoint, object body)
        {
            var host = Parameters["Host"];

            return(HttpClientUtils.HttpInvokeAsync(host, method, endpoint, body));
        }