本文整理汇总了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);
}
}