以下是使用C#发送HTTP请求的示例代码:
```csharp
using System;
using System.Net;
using System.IO;
class Program
{
static void Main(string[] args)
{
// 创建一个Web请求对象
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("Example Domain");
// 设置请求方法为GET
request.Method = "GET";
// 发送请求并获取响应
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// 读取响应内容
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string responseText = reader.ReadToEnd();
Console.WriteLine(responseText);
}
}
}
```
这个示例代码使用了`HttpWebRequest`和`HttpWebResponse`类来发送HTTP请求和获取响应。在创建`HttpWebRequest`对象时,需要指定请求的URL,并设置请求方法。在发送请求后,可以通过`HttpWebResponse`对象获取响应,并使用`StreamReader`类读取响应内容。
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://ip.hahado.cn/ip");
WebProxy myProxy = new WebProxy();
Uri newUri = new Uri("http://ip.hahado.cn:39010");
myProxy.Address = newUri;
myProxy.Credentials = new NetworkCredential("username", "password");
request.Proxy = myProxy;