简体   繁体   English

如何在HttpWebRequest中更改请求IP?

[英]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. 为了安全起见,此Web服务仅接受来自先前已通知他们的IP地址的请求。

Since I'm developing locally, my IP changes almost every day. 由于我在本地开发,因此我的IP几乎每天都在变化。 Is there a way for me to change the IP address of a HttpWebRequest so that I can test the Webservice calls locally? 有没有办法更改HttpWebRequest的IP地址,以便可以在本地测试Webservice调用?

This webservice is accessed through a https address and the methods must be sent via POST. 该Web服务通过https地址访​​问,并且必须通过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. 不可以,但是如果您设法更改了请求的源IP地址,那么您要做的就是IP欺骗。 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. 问题在于,源IP用于将响应路由回您的计算机,因此,由于您以某种方式设法更改了请求数据包中的IP地址,因此该响应永远都不会返回给您,因为这不是您的IP地址。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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