开发者

How to change the request IP in HttpWebRequest?

开发者 https://www.devze.com 2022-12-30 08:59 出处:网络
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

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.


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号