problema con status code + java
Publicado: 04 Oct 2012, 14:12
Hola buenas, tengo un problema y es que estoy con una aplicacion para obtener el status code en una petición el caso es que debuggeando con chrome me tira el status code 301 sin embargo con esta aplicación en java me tira el status code 200, haber si me hechan una mano. esta es la url que uso [Enlace externo eliminado para invitados]
Salu2! y gracias de antemano

Salu2! y gracias de antemano

Código: Seleccionar todo
import java.net.*;
import java.io.*;
public class MainClass {
public static void main(String args[]) {
URL u;
URLConnection uc;
String header;
String nextLine;
URLConnection urlConn = null;
InputStreamReader inStream = null;
BufferedReader buff = null;
try {
u = new URL("http://java.sun.com/jdc");
URLConnection connection = u.openConnection();
connection.connect();
// Cast to a HttpURLConnection
if ( connection instanceof HttpURLConnection)
{
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int code = httpConnection.getResponseCode();
System.out.println(code);
// do something with code .....
}
else
{
System.err.println ("error - not a http request!");
}
uc = u.openConnection();
for (int j = 1;; j++) {
header = uc.getHeaderField(j);
if (header == null)
break;
System.out.println(uc.getHeaderFieldKey(j) + " " + header);
}
// Create the URL obect that points
// at the default file index.html
urlConn = u.openConnection();
inStream = new InputStreamReader(
urlConn.getInputStream());
buff= new BufferedReader(inStream);
// Read and print the lines from index.html
while (true){
nextLine =buff.readLine();
if (nextLine !=null){
System.out.println(nextLine);
}
else{
break;
}
}
} catch (MalformedURLException e) {
System.err.println("not a URL I understand.");
} catch (IOException e) {
System.err.println(e);
}
}
}