holiveira
holiveira

Reputation: 4515

How to change the request IP in HttpWebRequest?

I'm developing a website that will connect to a credit card processing gateway webservice. For security purposes this webservice accepts requests only from IP addresses that were previously informed to them.

Since I'm developing locally, my IP changes almost every day. Is there a way for me to change the IP address of a HttpWebRequest so that I can test the Webservice calls locally?

This webservice is accessed through a https address and the methods must be sent via POST.

Upvotes: 4

Views: 8426

Answers (3)

HaBo
HaBo

Reputation: 14327

I know this is a old post. But I was able to get this work for me, hope this will be useful for someone in need of similar issue

  ServicePointManager.Expect100Continue = true;
            if (System.Web.HttpContext.Current.Request.IsLocal)
            {
                webRequest.ServicePoint.BindIPEndPointDelegate = delegate(
                ServicePoint servicePoint,
                IPEndPoint remoteEndPoint,
                int retryCount)
                {
                    return new IPEndPoint(
                        IPAddress.Parse("192.168.1.1"),
                        0);
                };
            }

Upvotes: 1

snies
snies

Reputation: 3521

You might want to check out JSONP if your data is in the JSON encoding as that is exactly for the purpose of requesting data from a webserver other than the one sending the original webpage.

Upvotes: 0

Chris Taylor
Chris Taylor

Reputation: 53729

No, but if you managed to changes the source IP address of your requests, what you would be doing is called IP spoofing. The problem is that the source IP is used to route responses back to your machine, so since you somehow managed to change the IP address in the request packets, the response would never get back to you because that is not your IP address.

Upvotes: 1

Related Questions