This is the code I used :
class ResponseCodeCheck
{
public static void main (String args[]) throws Exception
{
URL url = new URL("http://www.amazon.co.jp/gp/seller/sell-your-stuff.html");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int code = connection.getResponseCode();
System.out.println("Response code of the object is "+code);
if (code==200)
{
System.out.println("OK");
}
}
}
And it gave 404 for the URL while that URL is working fine.
Any reason why ?
CURLis saying:Please note
HTTP/1.1 301 MovedPermanently. Are you sure you have received404and not301? This is usual web practice, 301 header means that content was placed in some other location and user (browser) should navigate to it.Also please make sure that
HttpURLConnectionallows redirection.