I have a simple google app engine site running and its working fine and the webpage is being displayed in the browser.
If I use python to send a GET
request it works perfectly but for some reason when I use java for the same it gives a 404 Response
. My java code is :
public static void main(String args[]){
try {
URL u = new URL("http://localhost:8080/gendata/");
HttpURLConnection con = (HttpURLConnection) u.openConnection();
con.setRequestProperty("Content-Type", "text/plain");
con.setRequestMethod("GET");
if(con.getResponseCode() == HttpURLConnection.HTTP_OK){
System.out.println("Hola");
}else{
System.out.println(""+con.getResponseCode());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
My app engine get method :
class Writer(webapp2.RequestHandler):
def get(self):
self.response.write('''
<html>
<head><title>Hello</title>
</head>
<body>
<h1><center><b>This is test<br> FOO FOO
</b></center> </h1>
</body></html>
''')
Since I just started learning Java I wanted to know is the process different from python? And I also wanted to know if there is any Java library similar to the requests library in python ?
curl -v http://localhost:8080/gendata/
on the same machine you're running the Java on? – Dave Morrissey Jul 18 '14 at 20:51