我在 java Jersey REST 中开发了一个 Web 服务。我使用 HttpClient 来调用一个基本的 GET 方法。
在浏览器上使用此 URLhttp://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;
}
有什么线索吗?
更新
另外,我尝试http://192.168.9.160:8080/LocationRetreiverServer/rest/location
了(我的本地 IP),它给出了 Not Found 错误!