C# HttpWebRequest 多网卡指定IP下载

/// <summary>
        /// 获取指定网卡IP
        /// </summary>
        /// <param name="servicePoint"></param>
        /// <param name="remoteEndPoint"></param>
        /// <param name="retryCount"></param>
        /// <returns></returns>
        public IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
        {
            if (!string.IsNullOrWhiteSpace(_configuration.IP))
            {
                IPAddress address = IPAddress.Parse(_configuration.IP);
                return new IPEndPoint(address, 0);
            }
            return new IPEndPoint(IPAddress.Any, 0);
        }

public static void Main()
{

    HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://MyServer");

    request.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIPEndPointCallback);

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

}


本文作者:admin

本文链接:https://www.javalc.com/post/82.html

版权声明:本篇文章于2021-11-29,由admin发表,转载请注明出处:分享你我。如有疑问,请联系我们

vue3 + ts+vite+electron使用tinymce富文本框

发表评论

取消
扫码支持