Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 设置连接C的IP地址#_C#_Web_Connection_Ip - Fatal编程技术网

C# 设置连接C的IP地址#

C# 设置连接C的IP地址#,c#,web,connection,ip,C#,Web,Connection,Ip,我的应用程序中有一个web浏览器,我想更改即将加载页面的传入连接的IP。如何设置连接的IP地址?我以前用Java做过,但不知道如何用C做 下面是我如何在Java中创建新IP,并将其设置为使用Java中的IP打开页面: InetSocketAddress newIP=新的InetSocketAddress( InetAddress.getByAddress( 接下来,新字节[]{byte.parseByte(bts[0]), Byte.parseByte(bts[1])、Byte.parseByt

我的应用程序中有一个web浏览器,我想更改即将加载页面的传入连接的IP。如何设置连接的IP地址?我以前用Java做过,但不知道如何用C做

下面是我如何在Java中创建新IP,并将其设置为使用Java中的IP打开页面:

InetSocketAddress newIP=新的InetSocketAddress(
InetAddress.getByAddress(
接下来,新字节[]{byte.parseByte(bts[0]),
Byte.parseByte(bts[1])、Byte.parseByte(bts[2]),
Byte.parseByte(bts[3])}
), 
80);
URL=新URL(“http://google.com");
openConnection(新代理(Proxy.Type.HTTP,newIP));

现在我只需要在C#中重新创建它。

如果您想设置代理地址,可以在WebRequest上执行此操作:

using System;
using System.IO;
using System.Net;

class Program
{
    static void Main(string[] args)
    {
        WebRequest wr = WebRequest.Create("http://www.google.com");
        WebProxy proxy = new WebProxy("http://localhost:8888");
        wr.Proxy = proxy;
        StreamReader sr = new StreamReader(wr.GetResponse().GetResponseStream());

        Console.WriteLine(sr.ReadToEnd());
        Console.ReadLine();
    }
}
或者,如果您需要在应用程序范围内设置它,您可以设置
GlobalProxySelection。选择代理
,所有后续HTTP请求都将使用该代理:

using System;
using System.IO;
using System.Net;

class Program
{
    static void Main(string[] args)
    {
        WebProxy proxy = new WebProxy("http://localhost:8888");
        GlobalProxySelection.Select = proxy;

        WebRequest wr = WebRequest.Create("http://www.google.com");

        StreamReader sr = new StreamReader(wr.GetResponse().GetResponseStream());

        Console.WriteLine(sr.ReadToEnd());
        Console.ReadLine();
    }
}

你能告诉我们你从C#开始做什么吗?在众多的.net/第三方类中,您希望使用哪些类建立连接?