I am using GET REST call in java using the given code, but I am getting an error code : 404 i.e Not Found . But when I am using the same URL in the browser I am getting the output and it is working fine.I new to JAVA. May be I am passing the query parameters wrongly, but I am not getting it. I am working in NETBEANS 7.1.2. Please help.
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
public class Test {
private static String ENDPOINT ="http://wisekar.iitd.ernet.in/active/api_resources.php/method/mynode?";
public static void main(String[] args) throws IOException
{
URL url = new URL(ENDPOINT + "key=" + "mykey" );
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("GET");
OutputStreamWriter out = new OutputStreamWriter( httpCon.getOutputStream());
System.out.println(httpCon.getResponseCode());
System.out.println(httpCon.getResponseMessage());
out.close();
}
}
here mykey is the key given to me by the website.
I also want to print the response message on the output window or console. As I want to store it in the future for some extraction. Please Help.