简体   繁体   中英

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.

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);
                };
            }

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.

如果您的数据采用JSON编码,则可能要签出JSONP,因为这正是出于从发送原始网页的Web服务器请求数据的目的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM