我正在寻找通过互联网发送原始 http 字符串的最简单 方法。我不想摆弄 header 或 cookie 或 contents 属性,方法和所有“好”的东西。我希望它像 Fiddler 一样:
您将整个字符串写入文本框 (1),然后单击“执行”(2)。你就完成了 = 利润。
我只想输入一些文本,然后将其发送。仅此而已。
如果 Socket 类没有失败将我的消息发送到 HTTPS 服务器,那将是很棒的,例如,Fiddler 可以轻松完成。
请您参考如下方法:
你有没有试过使用System.Net.WebClient ?
示例来自:
using System;
using System.Net;
using System.IO;
public class Test
{
public static void Main (string[] args)
{
if (args == null || args.Length == 0)
{
throw new ApplicationException ("Specify the URI of the resource to retrieve.");
}
WebClient client = new WebClient ();
// Add a user agent header in case the
// requested URI contains a query.
client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Stream data = client.OpenRead (args[0]);
StreamReader reader = new StreamReader (data);
string s = reader.ReadToEnd ();
Console.WriteLine (s);
data.Close ();
reader.Close ();
}
