how to change originating IP in HttpWebRequest

前端 未结 2 1344
名媛妹妹
名媛妹妹 2020-11-28 07:36

I\'m running this application on a server that has assigned 5 IPs. I use HttpWebRequest to fetch some data from a website. But when I make the connection I have be able to s

2条回答
  •  萌比男神i
    2020-11-28 08:07

    Try this:

    System.Net.WebRequest request = System.Net.WebRequest.Create(link);
    request.ConnectionGroupName = "MyNameForThisGroup"; 
    ((HttpWebRequest)request).Referer = "http://application.com";
    using (System.Net.WebResponse response = request.GetResponse())
    {
        StreamReader sr = new StreamReader(response.GetResponseStream());
        return sr.ReadToEnd();
    }
    

    Then try setting the ConnectionGroupName to something distinct per source ip you wish to use.

    edit: use this in conjunction with the IP binding delegate from the answer above.

提交回复
热议问题