本文整理汇总了C#中Args.Encode方法的典型用法代码示例。如果您正苦于以下问题:C# Args.Encode方法的具体用法?C# Args.Encode怎么用?C# Args.Encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Args
的用法示例。
在下文中一共展示了Args.Encode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Attach
/// <summary>
/// Creates a socket to the Splunk server using the named index and
/// variable arguments.
/// </summary>
/// <param name="indexName">The index name.</param>
/// <param name="args">The variable arguments.</param>
/// <returns>The socket.</returns>
public Stream Attach(string indexName, Args args)
{
Stream stream;
if (this.service.Scheme == HttpService.SchemeHttps)
{
TcpClient tcp = new TcpClient();
tcp.Connect(this.service.Host, this.service.Port);
var sslStream = new SslStreamWrapper(tcp);
sslStream.AuthenticateAsClient(this.service.Host);
stream = sslStream;
}
else
{
Socket socket = this.service.Open(this.service.Port);
stream = new NetworkStream(socket, true);
}
string postUrl = "POST /services/receivers/stream";
if (indexName != null)
{
postUrl = postUrl + "?index=" + indexName;
}
if (args != null && args.Count > 0)
{
postUrl = postUrl + ((indexName == null) ? "?" : "&");
postUrl = postUrl + args.Encode();
}
string header = string.Format(
"{0} HTTP/1.1\r\n" +
"Host: {1}:{2}\r\n" +
"Accept-Encoding: identity\r\n" +
"Authorization: {3}\r\n" +
"X-Splunk-Input-Mode: Streaming\r\n\r\n",
postUrl,
this.service.Host,
this.service.Port,
this.service.Token);
var bytes = Encoding.UTF8.GetBytes(header);
stream.Write(bytes, 0, bytes.Length);
stream.Flush();
return stream;
}
示例2: Submit
/// <summary>
/// Submits the data to the named index using variable arguments.
/// </summary>
/// <param name="indexName">The named index.</param>
/// <param name="args">The variable arguments.</param>
/// <param name="data">The data.</param>
public void Submit(string indexName, Args args, string data)
{
string sendString = string.Empty;
RequestMessage request = new RequestMessage("POST");
request.Content = data;
if (indexName != null)
{
sendString = string.Format("?index={0}", indexName);
}
if (args != null && args.Count > 0)
{
sendString = sendString + ((indexName == null) ? "?" : "&");
sendString = sendString + args.Encode();
}
this.service.Send(
this.service.SimpleReceiverEndPoint + sendString, request);
}