首页 > 代码库 > 一个服务器上面配置多个IP ,实现指定IP的域名请求
一个服务器上面配置多个IP ,实现指定IP的域名请求
//配置多个IP命名
using System.Net;
//***************************************************************************
/// <summary> /// 通过设置这个属性,可以在发出连接的时候绑定客户端发出连接所使用的IP地址。 /// </summary> /// <param name="servicePoint"></param> /// <param name="remoteEndPoint"></param> /// <param name="retryCount"></param> /// <returns></returns> public static IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount) { return new IPEndPoint(IPAddress.Parse("192.168.1.1") , 0);//端口号 } /// <summary> /// 一个服务器上面配置多个IP 固定出网IP /// </summary> public static void MakeRequest() { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.baidu.com"); //设置本地的出口ip和端口 request.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIPEndPointCallback); if (ServicePointManager.DefaultConnectionLimit < 10) { ServicePointManager.DefaultConnectionLimit = 10; } //req.ServicePoint.ConnectionLimit=int.Max; //允许最大连接数 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.ToString(); }
HttpWebRequest的详细方法二:
System.Net.HttpWebRequest myRequest = null; System.Net.HttpWebResponse myResponse = null; Stream reqStream = null; Stream resStream = null; string signkey = "", url = ""; string sdateStr = DateTime.Now.AddDays(-6).ToString("yyyyMMdd") + "000001"; try { signkey = XH_ChannelKey;//key url = XH_ChannelUrl; //接口地址 url += "fromDate=" + sdateStr; url += "&version=1.4";//版本号 url += "&hmac=" + MD5Encrypt(signkey + sdateStr + "1.4"); //想服务器端发送请求,获取订单信息 myRequest = System.Net.WebRequest.Create(url) as System.Net.HttpWebRequest; //--------------------- c#中HttpWebRequest使用Proxy实现指定IP的域名请求 --------------------------------- //需要使用Proxy和其配置 (代理ip) ////System.Net.WebProxy proxy = new System.Net.WebProxy("115.238.128.138", 80); ////myRequest.Proxy = proxy; //------------------------------------------------------ myRequest.Timeout = 1000 * 60 * 1;//1分钟超时 1 minutes timeout myRequest.Method = "POST"; myResponse = myRequest.GetResponse() as System.Net.HttpWebResponse; Stream myResponseStream = myResponse.GetResponseStream(); StreamReader myStreamReader; myStreamReader = new StreamReader(myResponseStream, System.Text.Encoding.GetEncoding("utf-8")); //post返回的数据 string receiveData = http://www.mamicode.com/myStreamReader.ReadToEnd();"位置"), stacktrace.Length - stacktrace.IndexOf("位置")); Common.WriteTextLog("Error","", ex.Message + Environment.NewLine + errpoint); } finally { if (resStream != null) { resStream.Close(); } if (reqStream != null) { reqStream.Close(); } if (myResponse != null) { myResponse.Close(); } if (myRequest != null) { myRequest.Abort(); } ////特别留意这句Sleep的调用!! System.Threading.Thread.Sleep(16); }
一个服务器上面配置多个IP ,实现指定IP的域名请求
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。