Java代码显示请求重定向,但浏览器不重定向。为什么?

Java代码显示请求重定向,但浏览器不重定向。为什么?,java,Java,下面的url在我通过Java运行时给出了响应代码301。url是: 它根据java代码给出的重定向url是: 代码是: public class newTestURLConnection { public static void main(String[] args) throws IOException { String url="http://www.amazon.com/Kindle-Wireless-Reading-Display-Globally/dp/B00

下面的url在我通过Java运行时给出了响应代码301。url是: 它根据java代码给出的重定向url是:

代码是:

public class newTestURLConnection {
    public static void main(String[] args) throws IOException {
        String url="http://www.amazon.com/Kindle-Wireless-Reading-Display-Globally/dp/B003FSUDM4/ref=amb_link_353259562_2?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-10&pf_rd_r=11EYKTN682A79T370AM3&pf_rd_t=201&pf_rd_p=1270985982&pf_rd_i=B002Y27P3M";
        HttpURLConnection con =(HttpURLConnection) new URL( url ).openConnection();
        con.setInstanceFollowRedirects(false);

        con.connect();

        InputStream is = con.getInputStream();
        System.out.println(con.getHeaderField("Location"));
        System.out.println( "Response code: " + con.getResponseCode() );
    }
}
但当我在浏览器中打开url时,它不会重定向到:。有人能解释为什么会有这种差异吗

instanceFollowRedirects

protected boolean instanceFollowRedirects

    If true, the protocol will automatically follow redirects. If false, the protocol will not automatically follow redirects.

    This field is set by the setInstanceFollowRedirects method. Its value is returned by the getInstanceFollowRedirects method.

    Its default value is based on the value of the static followRedirects at HttpURLConnection construction time. 
这是从

有人能解释为什么会有这种差异吗

instanceFollowRedirects

protected boolean instanceFollowRedirects

    If true, the protocol will automatically follow redirects. If false, the protocol will not automatically follow redirects.

    This field is set by the setInstanceFollowRedirects method. Its value is returned by the getInstanceFollowRedirects method.

    Its default value is based on the value of the static followRedirects at HttpURLConnection construction time. 
可能是亚马逊根据请求头的不同做出了不同的响应;e、 g.用户代理标头中发送的内容

也许这是为了向真正的客户和网络爬虫/内容爬虫展示不同的结果

不管是什么原因,这两页之间的差异是非常微妙的。。。至少在人眼看来是这样


如果这不仅仅是一次性的事情(例如测试一些代码),我还应该询问您是否阅读过亚马逊的“使用条件”;e、 g.该位上写有:

未经亚马逊明确书面同意,不得为任何商业目的复制、复制、复制、出售、转售、访问或以其他方式利用亚马逊服务或其任何部分


你能试试302代码而不是301代码吗?