Created
June 1, 2018 10:07
-
-
Save cpoDesign/020390bd50c3b31b3f9b4c8def65ca99 to your computer and use it in GitHub Desktop.
Force request to specific IP address and port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string sendingIp = "192.168.0.1"; | |
int sendingPort = 5000; | |
Uri uri = new Uri("http://google.com"); | |
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(uri); | |
ServicePoint sp = ServicePointManager.FindServicePoint(uri); | |
sp.BindIPEndPointDelegate = | |
(servicePoint,remoteEp,retryCount) => | |
{ | |
return new IPEndPoint(IPAddress.Parse(sendingIp),sendingPort); | |
}; | |
var data = new StreamReader(wr.GetResponse().GetResponseStream()).ReadToEnd(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment