mercredi 2 mai 2018

change source ip address httpwebrequest

I have server with 5 valid IP addresses. i have to consume the web service with with these IP addresses. for security reasons i have to change my IP address every 4 hours. in order to do that i wrote a route an schedule it to execute on server but I'm looking for better solution. i found this and i tried it but it didn't work. the request didn't receive by destination service. here is my code:

private static string Call(string url)
{
    var request = (HttpWebRequest)WebRequest.Create(url);
    request.Timeout = 3 * 1000;
    request.Method = "GET";
    request.ServicePoint.BindIPEndPointDelegate = delegate
    {
        return new IPEndPoint(IPAddress.Parse("130.185.74.2"), 0);
    };

    var responseString = string.Empty;
    using (var webResponse = (HttpWebResponse)request.GetResponse())
    using (var responseStream = webResponse.GetResponseStream())
    using (var reader = new StreamReader(responseStream))
    {
        reader.BaseStream.ReadTimeout = 3 * 1000;
        responseString = reader.ReadToEnd();
    }

    return responseString;
}

did i miss something?




Aucun commentaire:

Enregistrer un commentaire