我在java Jersey REST中开发了一个Web服务。我使用HttpClient来调用一个基本的GET方法。HttpClient不与本地主机工作
在浏览器上使用此URL http://localhost:8080/myserver/rest/location
时,它可以正常工作。
使用此代码调用GET方法时,出现404 Not Found错误。
private static final String BASIC_URL = "http://localhost:8080/myserver/rest/location";
public static boolean isAlive() throws URISyntaxException, ClientProtocolException, IOException{
HttpClient httpclient = new DefaultHttpClient();
HttpGet get=new HttpGet(BASIC_URL);
System.out.println(get.getURI());
System.out.println("after adding all namevalues: "+get.getURI());
HttpResponse response = httpclient.execute(get);
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() != 200) {
System.out.println("response status="+statusLine.getStatusCode());
return false;
}
System.out.println("Response sent succesfully with status "+200);
return true;
}
任何线索?
UPDATE
而且,我想http://192.168.9.160:8080/LocationRetreiverServer/rest/location
(我的本地IP),它给了Not Found错误!
它在浏览器上显示什么? – 2013-04-24 13:49:58
它显示200 OK响应并显示一个字符串。 – 2013-04-24 13:58:40
你的泽西REST服务是否有可能返回404的逻辑? – 2013-04-24 14:05:21