当前位置: 首页>>代码示例>>C#>>正文


C# HttpRequest.GetBody方法代码示例

本文整理汇总了C#中HttpRequest.GetBody方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequest.GetBody方法的具体用法?C# HttpRequest.GetBody怎么用?C# HttpRequest.GetBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpRequest的用法示例。


在下文中一共展示了HttpRequest.GetBody方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Curl

        public void Curl(IManosContext ctx, string url, string method, string auth, string [] header_keys = null)
        {
            // TODO: Should we set the Host header automagically?
            Uri u = null;
            if (!Uri.TryCreate (url, UriKind.Absolute, out u)) {
                CurlError (ctx, "Url is invalid: {0}", url);
                return;
            }

            if (u.Scheme == "https") {
                CurlError (ctx, "https connections are not supported yet.");
                return;
            }

            {
                // TODO: Manos will handle this DNS stuff internally soon.
                IPAddress [] addrs = Dns.GetHostAddresses (u.Host);
                if (addrs.Length == 0) {
                    CurlError (ctx, "Could not resolve host: {0}", u.Host);
                    return;
                }

                UriBuilder builder = new UriBuilder (u);
                builder.Host = addrs [0].ToString ();

                url = builder.ToString ();
            }

            HttpRequest r = new HttpRequest (url) {
                Method = GetHttpMethod (method),
            };

            r.Headers.SetNormalizedHeader ("Host", u.Host);

            if (header_keys != null) {
                var header_vals = ctx.Request.Data.GetList ("header_vals");
                for (int i = 0; i < header_keys.Length; i++) {
               		r.Headers.SetHeader (header_keys [i], header_vals [i].SafeValue);
                }
            }

            if (auth == "basic")
                HttpUtility.AddBasicAuthentication (r, ctx.Request.Data ["username"], ctx.Request.Data ["password"]);

            AddBody (ctx, r);

            r.OnResponse += (response) => {

                var res = new Dictionary<object,object> ();
                var response_md = new StringBuilder ();
                var request_md = new StringBuilder ();

                r.WriteMetadata (request_md);
                response.WriteMetadata (response_md);

                res ["header"] = PrettyPrintMetadata (response_md.ToString ());
                res ["request"]  = PrettyPrintMetadata (request_md.ToString ()) + PrintBody (r.GetBody ());
                res ["body"] = "<div><pre>" + HttpUtility.HtmlEncode (response.PostBody) + "</pre></div>";

                ctx.Response.End (JSON.JsonEncode (res));
            };

            try {
                r.Execute ();
            } catch (Exception e) {
                CurlError (ctx, e.Message);
            }
        }
开发者ID:nuxleus,项目名称:Froxy,代码行数:68,代码来源:Froxy.cs


注:本文中的HttpRequest.GetBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。