当我通过 Java 运行以下网址时,它会给出响应代码 301。网址是: 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 并且它根据java代码提供的重定向网址是:
http://www.amazon.com/Kindle-Keyboard-Free-Wi-Fi-Display/dp/B004HZYA6E
代码是:
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 时,它不会重定向到:http://www.amazon.com/Kindle-Keyboard-Free-Wi-Fi-Display/dp/B004HZYA6E。谁能提出为什么会有这种差异?