简体   繁体   English

重定向HTML页面

[英]Redirecting html page

Here is my problem : 这是我的问题:

I have to perform post from java code to some page , get the data and parse it. 我必须执行从Java代码到某些页面的发布,获取数据并解析它。 The problem is that only my country ip can post to this page. 问题是只有我所在国家的ip可以发布到此页面。 Requests from another ip's are rejected. 来自另一个IP的请求被拒绝。 I want to find workaround. 我想找到解决方法。 I have added my html page on server in my country (this server accessible from all ips) . 我在我的国家/地区的服务器上添加了html页面(该服务器可从所有ips访问)。 Now I am sending a get request (in open to all server) to this page from Java code. 现在,我正在从Java代码向此页面发送一个get请求(对所有服务器开放)。 What I want to do is to redirect my html page to post to the original page. 我想做的是重定向我的HTML页面以发布到原始页面。

I tried to use redirection , but it doesn't work - from Java code I get my html page and not redirected one. 我尝试使用重定向,但是它不起作用-从Java代码中,我得到了html页面,但未重定向页面。

Is there any solution or my problem ? 有什么解决方案或我的问题吗?

Thanks 谢谢

I tried to use redirection , but it doesn't work - from Java code I get my html page and not redirected one. 我尝试使用重定向,但是它不起作用-从Java代码中,我得到了html页面,但未重定向页面。

Yes it wont work because redirection works on client side. 是的,因为重定向在客户端起作用,所以它不起作用。 You perform a request to your HTML page which sends back a redirect header and your Java implementation doesnt know what to do with it. 您对HTML页面执行请求,该请求发送回重定向标头,而Java实现不知道该如何处理。 Even if it did, it had to make a new request to redirected page, which means that the request to the redirected page would still be from a denied IP. 即使这样做,它也必须向重定向页面发出新请求,这意味着对重定向页面的请求仍将来自拒绝的IP。

Another option is that your redirection HTML uses JavaScript window.location.assign or something like that. 另一个选择是您的重定向HTML使用JavaScript window.location.assign或类似的东西。 The point remains the same, beacause this also is a client side solution. 要点保持不变,因为这也是客户端解决方案。

You have to use some kind of server side language on the host where you placed your HTML and in that server side script you have to perform a (post or get as you wish) request to only-your-country URL. 您必须在放置HTML的主机上使用某种服务器端语言,并且在该服务器端脚本中,必须对您所在国家/地区的URL执行(发布或获取所需的)请求。 This way this only-your-country URL will see that the request came from the host where the script was, not the client itself. 这样,这个只有您所在国家/地区的网址将看到请求来自脚本所在的主机,而不是客户端本身。

For example if you can use java as your server side language on the place where currently your redirection html is, then you can check out this thread: How to send simple http post request with post parameters in java 例如,如果您可以在当前重定向HTML的位置上将Java用作服务器端语言,则可以检查以下线程: 如何在Java中发送带有post参数的简单http post请求

You need a reverse proxy installed on a server located in your country. 您需要在您所在国家/地区的服务器上安装反向代理 If you make a request to this reverse proxy, it will make a request to the only-your-country server and when it gets a response it will forward it to you. 如果您对此反向代理提出请求,它将向您唯一的国家/地区服务器发出请求,并且在收到响应后会将其转发给您。 So the only-your-country server will receive the same request as you make to the reverse proxy, but with a source IP address changed to the IP of the reverse proxy server. 因此,您唯一的国家/地区服务器将收到与反向代理服务器相同的请求,但是源IP地址已更改为反向代理服务器的IP。

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

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